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-preq.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-preq.h
"
22
#include "ns3/address-utils.h"
23
#include "ns3/assert.h"
24
#include "ns3/packet.h"
25
26
namespace
ns3 {
27
namespace
dot11s {
28
/*************************
29
* DestinationAddressUnit
30
************************/
31
DestinationAddressUnit::DestinationAddressUnit
() :
32
m_do (false), m_rf (false), m_usn (false), m_destinationAddress (
Mac48Address
()), m_destSeqNumber (0)
33
{
34
}
35
void
36
DestinationAddressUnit::SetFlags
(
bool
doFlag,
bool
rfFlag,
bool
usnFlag)
37
{
38
m_do
= doFlag;
39
m_rf
= rfFlag;
40
m_usn
= usnFlag;
41
}
42
43
void
44
DestinationAddressUnit::SetDestSeqNumber
(uint32_t dest_seq_number)
45
{
46
m_destSeqNumber
= dest_seq_number;
47
if
(
m_destSeqNumber
!= 0)
48
{
49
m_usn
=
true
;
50
}
51
}
52
void
53
DestinationAddressUnit::SetDestinationAddress
(
Mac48Address
dest_address)
54
{
55
m_destinationAddress
= dest_address;
56
}
57
bool
58
DestinationAddressUnit::IsDo
()
59
{
60
return
m_do
;
61
}
62
63
bool
64
DestinationAddressUnit::IsRf
()
65
{
66
return
m_rf
;
67
}
68
bool
69
DestinationAddressUnit::IsUsn
()
70
{
71
return
m_usn
;
72
}
73
uint32_t
74
DestinationAddressUnit::GetDestSeqNumber
()
const
75
{
76
return
m_destSeqNumber
;
77
}
78
Mac48Address
79
DestinationAddressUnit::GetDestinationAddress
()
const
80
{
81
return
m_destinationAddress
;
82
}
83
/********************************
84
* IePreq
85
*******************************/
86
IePreq::~IePreq
()
87
{
88
}
89
IePreq::IePreq
() :
90
m_maxSize (32), m_flags (0), m_hopCount (0), m_ttl (0), m_preqId (0), m_originatorAddress (
91
Mac48Address
::GetBroadcast ()), m_originatorSeqNumber (0), m_lifetime (0), m_metric (0),
92
m_destCount (0)
93
{
94
}
95
WifiInformationElementId
96
IePreq::ElementId
()
const
97
{
98
return
IE11S_PREQ
;
99
}
100
void
101
IePreq::SetUnicastPreq
()
102
{
103
m_flags
|= 1 << 1;
104
}
105
106
void
107
IePreq::SetNeedNotPrep
()
108
{
109
m_flags
|= 1 << 2;
110
}
111
void
112
IePreq::SetHopcount
(uint8_t hopcount)
113
{
114
m_hopCount
= hopcount;
115
}
116
void
117
IePreq::SetTTL
(uint8_t ttl)
118
{
119
m_ttl
= ttl;
120
}
121
void
122
IePreq::SetPreqID
(uint32_t preq_id)
123
{
124
m_preqId
= preq_id;
125
}
126
void
127
IePreq::SetMetric
(uint32_t metric)
128
{
129
m_metric
= metric;
130
}
131
void
132
IePreq::SetOriginatorAddress
(
Mac48Address
originator_address)
133
{
134
m_originatorAddress
= originator_address;
135
}
136
void
137
IePreq::SetOriginatorSeqNumber
(uint32_t originator_seq_number)
138
{
139
m_originatorSeqNumber
= originator_seq_number;
140
}
141
void
142
IePreq::SetLifetime
(uint32_t lifetime)
143
{
144
m_lifetime
= lifetime;
145
}
146
void
147
IePreq::SetDestCount
(uint8_t dest_count)
148
{
149
m_destCount
= dest_count;
150
}
151
bool
152
IePreq::IsUnicastPreq
()
const
153
{
154
return
(
m_flags
& (1 << 1));
155
}
156
bool
157
IePreq::IsNeedNotPrep
()
const
158
{
159
return
(
m_flags
& (1 << 2));
160
}
161
uint8_t
162
IePreq::GetHopCount
()
const
163
{
164
return
m_hopCount
;
165
}
166
uint8_t
167
IePreq::GetTtl
()
const
168
{
169
return
m_ttl
;
170
}
171
uint32_t
172
IePreq::GetPreqID
()
const
173
{
174
return
m_preqId
;
175
}
176
uint32_t
177
IePreq::GetMetric
()
const
178
{
179
return
m_metric
;
180
}
181
Mac48Address
182
IePreq::GetOriginatorAddress
()
const
183
{
184
return
m_originatorAddress
;
185
}
186
uint32_t
187
IePreq::GetOriginatorSeqNumber
()
const
188
{
189
return
m_originatorSeqNumber
;
190
}
191
uint32_t
192
IePreq::GetLifetime
()
const
193
{
194
return
m_lifetime
;
195
}
196
197
uint8_t
198
IePreq::GetDestCount
()
const
199
{
200
return
m_destCount
;
201
}
202
void
203
IePreq::DecrementTtl
()
204
{
205
m_ttl
--;
206
m_hopCount
++;
207
}
208
void
209
IePreq::IncrementMetric
(uint32_t metric)
210
{
211
m_metric
+= metric;
212
}
213
void
214
IePreq::SerializeInformationField
(
Buffer::Iterator
i)
const
215
{
216
i.
WriteU8
(
m_flags
);
217
i.
WriteU8
(
m_hopCount
);
218
i.
WriteU8
(
m_ttl
);
219
i.
WriteHtolsbU32
(
m_preqId
);
220
WriteTo
(i,
m_originatorAddress
);
221
i.
WriteHtolsbU32
(
m_originatorSeqNumber
);
222
i.
WriteHtolsbU32
(
m_lifetime
);
223
i.
WriteHtolsbU32
(
m_metric
);
224
i.
WriteU8
(
m_destCount
);
225
int
written = 0;
226
for
(std::vector<
Ptr<DestinationAddressUnit>
>::const_iterator j =
m_destinations
.begin (); j
227
!=
m_destinations
.end (); j++)
228
{
229
uint8_t flags = 0;
230
if
((*j)->IsDo ())
231
{
232
flags |= 1 << 0;
233
}
234
if
((*j)->IsRf ())
235
{
236
flags |= 1 << 1;
237
}
238
if
((*j)->IsUsn ())
239
{
240
flags |= 1 << 2;
241
}
242
i.
WriteU8
(flags);
243
WriteTo
(i, (*j)->GetDestinationAddress ());
244
i.
WriteHtolsbU32
((*j)->GetDestSeqNumber ());
245
written++;
246
if
(written >
m_maxSize
)
247
{
248
break
;
249
}
250
}
251
}
252
uint8_t
253
IePreq::DeserializeInformationField
(
Buffer::Iterator
start
, uint8_t length)
254
{
255
Buffer::Iterator
i =
start
;
256
m_flags
= i.
ReadU8
();
257
m_hopCount
= i.
ReadU8
();
258
m_ttl
= i.
ReadU8
();
259
m_preqId
= i.
ReadLsbtohU32
();
260
ReadFrom
(i,
m_originatorAddress
);
261
m_originatorSeqNumber
= i.
ReadLsbtohU32
();
262
m_lifetime
= i.
ReadLsbtohU32
();
263
m_metric
= i.
ReadLsbtohU32
();
264
m_destCount
= i.
ReadU8
();
265
for
(
int
j = 0; j <
m_destCount
; j++)
266
{
267
Ptr<DestinationAddressUnit>
new_element = Create<DestinationAddressUnit> ();
268
bool
doFlag =
false
;
269
bool
rfFlag =
false
;
270
bool
usnFlag =
false
;
271
uint8_t flags = i.
ReadU8
();
272
if
(flags & (1 << 0))
273
{
274
doFlag =
true
;
275
}
276
if
(flags & (1 << 1))
277
{
278
rfFlag =
true
;
279
}
280
if
(flags & (1 << 2))
281
{
282
usnFlag =
true
;
283
}
284
new_element->
SetFlags
(doFlag, rfFlag, usnFlag);
285
Mac48Address
addr;
286
ReadFrom
(i, addr);
287
new_element->
SetDestinationAddress
(addr);
288
new_element->
SetDestSeqNumber
(i.
ReadLsbtohU32
());
289
m_destinations
.push_back (new_element);
290
NS_ASSERT
(28 + j * 11 < length);
291
}
292
return
i.
GetDistanceFrom
(start);
293
}
294
uint8_t
295
IePreq::GetInformationFieldSize
()
const
296
{
297
uint8_t retval = 1
//Flags
298
+ 1
//Hopcount
299
+ 1
//TTL
300
+ 4
//PREQ ID
301
+ 6
//Source address (originator)
302
+ 4
//Originator seqno
303
+ 4
//Lifetime
304
+ 4
//metric
305
+ 1;
//destination count
306
if
(
m_destCount
>
m_maxSize
)
307
{
308
retval += (
m_maxSize
* 11);
309
}
310
else
311
{
312
retval += (
m_destCount
* 11);
313
}
314
return
retval;
315
}
316
void
317
IePreq::Print
(std::ostream &os)
const
318
{
319
os << std::endl <<
"<information_element id="
<<
ElementId
() <<
">"
<< std::endl;
320
os <<
" originator address = "
<<
m_originatorAddress
<< std::endl;
321
os <<
" TTL = "
<< (uint16_t)
m_ttl
<< std::endl;
322
os <<
" hop count = "
<< (uint16_t)
m_hopCount
<< std::endl;
323
os <<
" metric = "
<<
m_metric
<< std::endl;
324
os <<
" seqno = "
<<
m_originatorSeqNumber
<< std::endl;
325
os <<
" lifetime = "
<<
m_lifetime
<< std::endl;
326
os <<
" preq ID = "
<<
m_preqId
<< std::endl;
327
os <<
" Destinations are:"
<< std::endl;
328
for
(
int
j = 0; j <
m_destCount
; j++)
329
{
330
os <<
" "
<<
m_destinations
[j]->GetDestinationAddress () << std::endl;
331
}
332
os <<
"</information_element>"
<< std::endl;
333
}
334
std::vector<Ptr<DestinationAddressUnit> >
335
IePreq::GetDestinationList
()
336
{
337
return
m_destinations
;
338
}
339
void
340
IePreq::AddDestinationAddressElement
(
bool
doFlag,
bool
rfFlag,
Mac48Address
dest_address,
341
uint32_t dest_seq_number)
342
{
343
for
(std::vector<
Ptr<DestinationAddressUnit>
>::const_iterator i =
m_destinations
.begin (); i
344
!=
m_destinations
.end (); i++)
345
{
346
if
((*i)->GetDestinationAddress () == dest_address)
347
{
348
return
;
349
}
350
}
351
//TODO: check overflow
352
Ptr<DestinationAddressUnit>
new_element = Create<DestinationAddressUnit> ();
353
new_element->
SetFlags
(doFlag, rfFlag, (dest_seq_number == 0));
354
new_element->
SetDestinationAddress
(dest_address);
355
new_element->
SetDestSeqNumber
(dest_seq_number);
356
m_destinations
.push_back (new_element);
357
m_destCount
++;
358
}
359
void
360
IePreq::DelDestinationAddressElement
(
Mac48Address
dest_address)
361
{
362
for
(std::vector<
Ptr<DestinationAddressUnit>
>::iterator i =
m_destinations
.begin (); i
363
!=
m_destinations
.end (); i++)
364
{
365
if
((*i)->GetDestinationAddress () == dest_address)
366
{
367
m_destinations
.erase (i);
368
m_destCount
--;
369
break
;
370
}
371
}
372
}
373
void
374
IePreq::ClearDestinationAddressElements
()
375
{
376
for
(std::vector<
Ptr<DestinationAddressUnit>
>::iterator j =
m_destinations
.begin (); j
377
!=
m_destinations
.end (); j++)
378
{
379
(*j) = 0;
380
}
381
m_destinations
.clear ();
382
m_destCount
= 0;
383
}
384
bool
385
operator==
(
const
DestinationAddressUnit
& a,
const
DestinationAddressUnit
& b)
386
{
387
return
(a.
m_do
== b.
m_do
&& a.
m_rf
== b.
m_rf
&& a.
m_usn
== b.
m_usn
&& a.
m_destinationAddress
388
== b.
m_destinationAddress
&& a.
m_destSeqNumber
== b.
m_destSeqNumber
);
389
}
390
bool
391
operator==
(
const
IePreq
& a,
const
IePreq
& b)
392
{
393
bool
ok = (a.
m_flags
== b.
m_flags
&& a.
m_hopCount
== b.
m_hopCount
&& a.
m_ttl
== b.
m_ttl
&& a.
m_preqId
394
== b.
m_preqId
&& a.
m_originatorAddress
== b.
m_originatorAddress
&& a.
m_originatorSeqNumber
395
== b.
m_originatorSeqNumber
&& a.
m_lifetime
== b.
m_lifetime
&& a.
m_metric
== b.
m_metric
&& a.
m_destCount
396
== b.
m_destCount
);
397
398
if
(!ok)
399
{
400
return
false
;
401
}
402
if
(a.
m_destinations
.size () != b.
m_destinations
.size ())
403
{
404
return
false
;
405
}
406
for
(
size_t
i = 0; i < a.
m_destinations
.size (); ++i)
407
{
408
if
(!(*(
PeekPointer
(a.
m_destinations
[i])) == *(
PeekPointer
(b.
m_destinations
[i]))))
409
{
410
return
false
;
411
}
412
}
413
return
true
;
414
}
415
bool
416
IePreq::MayAddAddress
(
Mac48Address
originator)
417
{
418
if
(
m_originatorAddress
!= originator)
419
{
420
return
false
;
421
}
422
if
(
m_destinations
[0]->GetDestinationAddress () ==
Mac48Address::GetBroadcast
())
423
{
424
return
false
;
425
}
426
if
((
GetInformationFieldSize
() + 11) > 255)
427
{
428
return
false
;
429
}
430
return
true
;
431
}
432
bool
433
IePreq::IsFull
()
const
434
{
435
return
((
GetInformationFieldSize
() + 11) > 255);
436
}
437
std::ostream &
438
operator <<
(std::ostream &os,
const
IePreq
&a)
439
{
440
a.
Print
(os);
441
return
os;
442
}
443
}
// namespace dot11s
444
}
// namespace ns3
445
src
mesh
model
dot11s
ie-dot11s-preq.cc
Generated on Tue May 14 2013 11:08:28 for ns-3 by
1.8.1.2