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
uan-header-rc.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19
*/
20
21
22
#include "
uan-header-rc.h
"
23
24
#include <set>
25
26
namespace
ns3 {
27
28
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderRcData);
29
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderRcRts);
30
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderRcCtsGlobal);
31
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderRcCts);
32
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderRcAck);
33
34
UanHeaderRcData::UanHeaderRcData
()
35
:
Header
(),
36
m_frameNo (0),
37
m_propDelay (
Seconds
(0))
38
{
39
}
40
41
UanHeaderRcData::UanHeaderRcData
(uint8_t frameNo,
Time
propDelay)
42
:
Header
(),
43
m_frameNo (frameNo),
44
m_propDelay (propDelay)
45
{
46
47
}
48
49
UanHeaderRcData::~UanHeaderRcData
()
50
{
51
}
52
53
TypeId
54
UanHeaderRcData::GetTypeId
()
55
{
56
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderRcData"
)
57
.
SetParent
<
Header
> ()
58
.AddConstructor<UanHeaderRcData> ()
59
;
60
return
tid;
61
}
62
63
void
64
UanHeaderRcData::SetFrameNo
(uint8_t no)
65
{
66
m_frameNo
= no;
67
}
68
69
void
70
UanHeaderRcData::SetPropDelay
(
Time
propDelay)
71
{
72
m_propDelay
= propDelay;
73
}
74
75
uint8_t
76
UanHeaderRcData::GetFrameNo
(
void
)
const
77
{
78
return
m_frameNo
;
79
}
80
81
Time
82
UanHeaderRcData::GetPropDelay
(
void
)
const
83
{
84
return
m_propDelay
;
85
}
86
87
uint32_t
88
UanHeaderRcData::GetSerializedSize
(
void
)
const
89
{
90
return
1 + 2;
91
}
92
93
void
94
UanHeaderRcData::Serialize
(
Buffer::Iterator
start
)
const
95
{
96
start.
WriteU8
(
m_frameNo
);
97
start.
WriteU16
( (uint16_t)(1000.0 *
m_propDelay
.
GetSeconds
() + 0.5));
98
}
99
uint32_t
100
UanHeaderRcData::Deserialize
(
Buffer::Iterator
start
)
101
{
102
Buffer::Iterator
rbuf =
start
;
103
104
m_frameNo
= start.
ReadU8
();
105
m_propDelay
=
Seconds
( ((
double
) start.
ReadU16
()) / 1000.0 );
106
107
return
rbuf.
GetDistanceFrom
(start);
108
}
109
110
void
111
UanHeaderRcData::Print
(std::ostream &os)
const
112
{
113
os <<
"Frame No="
<< (uint32_t)
m_frameNo
<<
" Prop Delay="
<<
m_propDelay
.
GetSeconds
();
114
}
115
116
TypeId
117
UanHeaderRcData::GetInstanceTypeId
(
void
)
const
118
{
119
return
GetTypeId
();
120
}
121
122
123
UanHeaderRcRts::UanHeaderRcRts
()
124
:
Header
(),
125
m_frameNo (0),
126
m_noFrames (0),
127
m_length (0),
128
m_timeStamp (
Seconds
(0)),
129
m_retryNo (0)
130
{
131
132
}
133
134
UanHeaderRcRts::UanHeaderRcRts
(uint8_t frameNo, uint8_t retryNo, uint8_t noFrames, uint16_t length,
Time
timeStamp)
135
:
Header
(),
136
m_frameNo (frameNo),
137
m_noFrames (noFrames),
138
m_length (length),
139
m_timeStamp (timeStamp),
140
m_retryNo (retryNo)
141
{
142
143
}
144
145
UanHeaderRcRts::~UanHeaderRcRts
()
146
{
147
148
}
149
150
TypeId
151
UanHeaderRcRts::GetTypeId
()
152
{
153
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderRcRts"
)
154
.
SetParent
<
Header
> ()
155
.AddConstructor<UanHeaderRcRts> ()
156
;
157
return
tid;
158
159
}
160
161
void
162
UanHeaderRcRts::SetFrameNo
(uint8_t no)
163
{
164
m_frameNo
= no;
165
}
166
167
void
168
UanHeaderRcRts::SetNoFrames
(uint8_t no)
169
{
170
m_noFrames
= no;
171
}
172
173
void
174
UanHeaderRcRts::SetLength
(uint16_t length)
175
{
176
m_length
= length;
177
}
178
void
179
UanHeaderRcRts::SetTimeStamp
(
Time
timeStamp)
180
{
181
m_timeStamp
= timeStamp;
182
}
183
184
void
185
UanHeaderRcRts::SetRetryNo
(uint8_t no)
186
{
187
m_retryNo
= no;
188
}
189
uint8_t
190
UanHeaderRcRts::GetNoFrames
()
const
191
{
192
return
m_noFrames
;
193
}
194
195
uint16_t
196
UanHeaderRcRts::GetLength
()
const
197
{
198
return
m_length
;
199
}
200
201
Time
202
UanHeaderRcRts::GetTimeStamp
(
void
)
const
203
{
204
return
m_timeStamp
;
205
}
206
207
uint8_t
208
UanHeaderRcRts::GetRetryNo
(
void
)
const
209
{
210
return
m_retryNo
;
211
}
212
213
uint8_t
214
UanHeaderRcRts::GetFrameNo
(
void
)
const
215
{
216
return
m_frameNo
;
217
}
218
219
uint32_t
220
UanHeaderRcRts::GetSerializedSize
(
void
)
const
221
{
222
return
1 + 1 + 1 + 4 + 2;
223
}
224
225
void
226
UanHeaderRcRts::Serialize
(
Buffer::Iterator
start
)
const
227
{
228
start.
WriteU8
(
m_frameNo
);
229
start.
WriteU8
(
m_retryNo
);
230
start.
WriteU8
(
m_noFrames
);
231
start.
WriteU16
(
m_length
);
232
start.
WriteU32
((uint32_t)(
m_timeStamp
.
GetSeconds
() * 1000.0 + 0.5));
233
// start.WriteU16(uint16_t (m_timeStamp.GetSeconds ()*1000));
234
}
235
236
uint32_t
237
UanHeaderRcRts::Deserialize
(
Buffer::Iterator
start
)
238
{
239
Buffer::Iterator
rbuf =
start
;
240
m_frameNo
= rbuf.
ReadU8
();
241
m_retryNo
= rbuf.
ReadU8
();
242
m_noFrames
= rbuf.
ReadU8
();
243
m_length
= rbuf.
ReadU16
();
244
m_timeStamp
=
Seconds
( ((
double
) rbuf.
ReadU32
()) / 1000.0 );
245
// m_timeStamp = Seconds ( rbuf.ReadU16 ()/1000 );
246
return
rbuf.
GetDistanceFrom
(start);
247
}
248
249
void
250
UanHeaderRcRts::Print
(std::ostream &os)
const
251
{
252
os <<
"Frame #="
<< (uint32_t)
m_frameNo
<<
" Retry #="
<< (uint32_t)
m_retryNo
<<
" Num Frames="
<< (uint32_t)
m_noFrames
<<
"Length="
<<
m_length
<<
" Time Stamp="
<<
m_timeStamp
.
GetSeconds
();
253
}
254
255
TypeId
256
UanHeaderRcRts::GetInstanceTypeId
(
void
)
const
257
{
258
return
GetTypeId
();
259
}
260
261
262
263
264
UanHeaderRcCtsGlobal::UanHeaderRcCtsGlobal
()
265
:
Header
(),
266
m_retryRate (0),
267
m_rateNum (0)
268
{
269
270
}
271
272
UanHeaderRcCtsGlobal::UanHeaderRcCtsGlobal
(
Time
wt,
Time
ts, uint16_t rate, uint16_t retryRate)
273
:
Header
(),
274
m_timeStampTx (ts),
275
m_winTime (wt),
276
m_retryRate (retryRate),
277
m_rateNum (rate)
278
{
279
280
}
281
282
UanHeaderRcCtsGlobal::~UanHeaderRcCtsGlobal
()
283
{
284
285
}
286
287
TypeId
288
UanHeaderRcCtsGlobal::GetTypeId
()
289
{
290
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderRcCtsGlobal"
)
291
.
SetParent
<
Header
> ()
292
.AddConstructor<UanHeaderRcCtsGlobal> ()
293
;
294
return
tid;
295
296
}
297
298
299
void
300
UanHeaderRcCtsGlobal::SetRateNum
(uint16_t rate)
301
{
302
m_rateNum
= rate;
303
}
304
305
void
306
UanHeaderRcCtsGlobal::SetRetryRate
(uint16_t rate)
307
{
308
m_retryRate
= rate;
309
}
310
311
void
312
UanHeaderRcCtsGlobal::SetWindowTime
(
Time
t)
313
{
314
m_winTime
= t;
315
}
316
317
void
318
UanHeaderRcCtsGlobal::SetTxTimeStamp
(
Time
t)
319
{
320
m_timeStampTx
= t;
321
}
322
323
Time
324
UanHeaderRcCtsGlobal::GetWindowTime
(
void
)
const
325
{
326
return
m_winTime
;
327
}
328
329
Time
330
UanHeaderRcCtsGlobal::GetTxTimeStamp
(
void
)
const
331
{
332
return
m_timeStampTx
;
333
}
334
335
uint16_t
336
UanHeaderRcCtsGlobal::GetRetryRate
(
void
)
const
337
{
338
return
m_retryRate
;
339
}
340
341
uint16_t
342
UanHeaderRcCtsGlobal::GetRateNum
(
void
)
const
343
{
344
return
m_rateNum
;
345
}
346
uint32_t
347
UanHeaderRcCtsGlobal::GetSerializedSize
(
void
)
const
348
{
349
return
4 + 4 + 2 + 2;
350
}
351
352
void
353
UanHeaderRcCtsGlobal::Serialize
(
Buffer::Iterator
start
)
const
354
{
355
start.
WriteU16
(
m_rateNum
);
356
start.
WriteU16
(
m_retryRate
);
357
start.
WriteU32
( (uint32_t)(
m_timeStampTx
.
GetSeconds
() * 1000.0 + 0.5));
358
start.
WriteU32
( (uint32_t)(
m_winTime
.
GetSeconds
() * 1000.0 + 0.5));
359
}
360
361
uint32_t
362
UanHeaderRcCtsGlobal::Deserialize
(
Buffer::Iterator
start
)
363
{
364
Buffer::Iterator
rbuf =
start
;
365
m_rateNum
= rbuf.
ReadU16
();
366
m_retryRate
= rbuf.
ReadU16
();
367
m_timeStampTx
=
Seconds
( ( (
double
) rbuf.
ReadU32
()) / 1000.0 );
368
m_winTime
=
Seconds
( ( (
double
) rbuf.
ReadU32
()) / 1000.0 );
369
return
rbuf.
GetDistanceFrom
(start);
370
371
}
372
373
void
374
UanHeaderRcCtsGlobal::Print
(std::ostream &os)
const
375
{
376
os <<
"CTS Global (Rate #="
<<
m_rateNum
<<
", Retry Rate="
<<
m_retryRate
<<
", TX Time="
<<
m_timeStampTx
.
GetSeconds
() <<
", Win Time="
<<
m_winTime
.
GetSeconds
() <<
")"
;
377
}
378
379
TypeId
380
UanHeaderRcCtsGlobal::GetInstanceTypeId
(
void
)
const
381
{
382
return
GetTypeId
();
383
}
384
385
UanHeaderRcCts::UanHeaderRcCts
()
386
:
Header
(),
387
m_frameNo (0),
388
m_timeStampRts (
Seconds
(0)),
389
m_retryNo (0),
390
m_delay (
Seconds
(0)),
391
m_address (
UanAddress
::GetBroadcast ())
392
{
393
394
}
395
396
UanHeaderRcCts::UanHeaderRcCts
(uint8_t frameNo, uint8_t retryNo,
Time
ts,
Time
delay,
UanAddress
addr)
397
:
Header
(),
398
m_frameNo (frameNo),
399
m_timeStampRts (ts),
400
m_retryNo (retryNo),
401
m_delay (delay),
402
m_address (addr)
403
{
404
405
}
406
407
UanHeaderRcCts::~UanHeaderRcCts
()
408
{
409
410
}
411
412
TypeId
413
UanHeaderRcCts::GetTypeId
()
414
{
415
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderRcCts"
)
416
.
SetParent
<
Header
> ()
417
.AddConstructor<UanHeaderRcCts> ()
418
;
419
return
tid;
420
421
}
422
423
void
424
UanHeaderRcCts::SetFrameNo
(uint8_t frameNo)
425
{
426
m_frameNo
= frameNo;
427
}
428
429
void
430
UanHeaderRcCts::SetRtsTimeStamp
(
Time
timeStamp)
431
{
432
m_timeStampRts
= timeStamp;
433
}
434
435
436
void
437
UanHeaderRcCts::SetDelayToTx
(
Time
delay)
438
{
439
m_delay
= delay;
440
}
441
442
void
443
UanHeaderRcCts::SetRetryNo
(uint8_t no)
444
{
445
m_retryNo
= no;
446
}
447
448
void
449
UanHeaderRcCts::SetAddress
(
UanAddress
addr)
450
{
451
m_address
= addr;
452
}
453
uint8_t
454
UanHeaderRcCts::GetFrameNo
()
const
455
{
456
return
m_frameNo
;
457
}
458
459
Time
460
UanHeaderRcCts::GetRtsTimeStamp
(
void
)
const
461
{
462
return
m_timeStampRts
;
463
}
464
465
Time
466
UanHeaderRcCts::GetDelayToTx
(
void
)
const
467
{
468
return
m_delay
;
469
}
470
471
uint8_t
472
UanHeaderRcCts::GetRetryNo
()
const
473
{
474
return
m_retryNo
;
475
}
476
477
UanAddress
478
UanHeaderRcCts::GetAddress
()
const
479
{
480
return
m_address
;
481
}
482
483
uint32_t
484
UanHeaderRcCts::GetSerializedSize
(
void
)
const
485
{
486
return
1 + 1 + 1 + 4 + 4;
487
}
488
489
490
void
491
UanHeaderRcCts::Serialize
(
Buffer::Iterator
start
)
const
492
{
493
start.
WriteU8
(
m_address
.
GetAsInt
());
494
start.
WriteU8
(
m_frameNo
);
495
start.
WriteU8
(
m_retryNo
);
496
start.
WriteU32
((uint32_t)(
m_timeStampRts
.
GetSeconds
() * 1000.0 + 0.5));
497
start.
WriteU32
((uint32_t)(
m_delay
.
GetSeconds
() * 1000.0 + 0.5));
498
}
499
500
uint32_t
501
UanHeaderRcCts::Deserialize
(
Buffer::Iterator
start
)
502
{
503
Buffer::Iterator
rbuf =
start
;
504
m_address
=
UanAddress
(rbuf.
ReadU8
());
505
m_frameNo
= rbuf.
ReadU8
();
506
m_retryNo
= rbuf.
ReadU8
();
507
m_timeStampRts
=
Seconds
( ( (
double
) rbuf.
ReadU32
()) / 1000.0 );
508
m_delay
=
Seconds
( ( (
double
) rbuf.
ReadU32
()) / 1000.0 );
509
510
return
rbuf.
GetDistanceFrom
(start);
511
}
512
513
void
514
UanHeaderRcCts::Print
(std::ostream &os)
const
515
{
516
os <<
"CTS (Addr="
<<
m_address
<<
" Frame #="
<< (uint32_t)
m_frameNo
<<
" Retry #="
<< (uint32_t)
m_retryNo
<<
" RTS Rx Timestamp="
<<
m_timeStampRts
.
GetSeconds
() <<
" Delay until TX="
<<
m_delay
.
GetSeconds
() <<
")"
;
517
}
518
519
TypeId
520
UanHeaderRcCts::GetInstanceTypeId
(
void
)
const
521
{
522
return
GetTypeId
();
523
}
524
525
UanHeaderRcAck::UanHeaderRcAck
()
526
: m_frameNo (0)
527
{
528
}
529
530
UanHeaderRcAck::~UanHeaderRcAck
()
531
{
532
m_nackedFrames
.clear ();
533
}
534
535
TypeId
536
UanHeaderRcAck::GetTypeId
()
537
{
538
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderRcAck"
)
539
.
SetParent
<
Header
> ()
540
.AddConstructor<UanHeaderRcAck> ()
541
;
542
return
tid;
543
}
544
545
void
546
UanHeaderRcAck::SetFrameNo
(uint8_t noFrames)
547
{
548
m_frameNo
= noFrames;
549
}
550
551
void
552
UanHeaderRcAck::AddNackedFrame
(uint8_t
frame
)
553
{
554
m_nackedFrames
.insert (frame);
555
}
556
557
const
std::set<uint8_t> &
558
UanHeaderRcAck::GetNackedFrames
(
void
)
const
559
{
560
return
m_nackedFrames
;
561
}
562
563
uint8_t
564
UanHeaderRcAck::GetFrameNo
(
void
)
const
565
{
566
return
m_frameNo
;
567
}
568
569
uint8_t
570
UanHeaderRcAck::GetNoNacks
(
void
)
const
571
{
572
return
m_nackedFrames
.size ();
573
}
574
575
uint32_t
576
UanHeaderRcAck::GetSerializedSize
(
void
)
const
577
{
578
return
1 + 1 +
GetNoNacks
();
579
}
580
581
void
582
UanHeaderRcAck::Serialize
(
Buffer::Iterator
start
)
const
583
{
584
start.
WriteU8
(
m_frameNo
);
585
start.
WriteU8
(
GetNoNacks
());
586
std::set<uint8_t>::iterator it =
m_nackedFrames
.begin ();
587
for
(; it !=
m_nackedFrames
.end (); it++)
588
{
589
start.
WriteU8
(*it);
590
}
591
}
592
593
uint32_t
594
UanHeaderRcAck::Deserialize
(
Buffer::Iterator
start
)
595
{
596
Buffer::Iterator
rbuf =
start
;
597
m_frameNo
= rbuf.
ReadU8
();
598
uint8_t noAcks = rbuf.
ReadU8
();
599
m_nackedFrames
.clear ();
600
for
(uint32_t i = 0; i < noAcks; i++)
601
{
602
m_nackedFrames
.insert (rbuf.
ReadU8
());
603
}
604
return
rbuf.
GetDistanceFrom
(start);
605
}
606
607
void
608
UanHeaderRcAck::Print
(std::ostream &os)
const
609
{
610
os <<
"# Frames="
<< (uint32_t)
m_frameNo
<<
" # nacked="
<< (uint32_t)
GetNoNacks
() <<
" Nacked: "
;
611
if
(
GetNoNacks
() > 0)
612
{
613
std::set<uint8_t>::iterator it =
m_nackedFrames
.begin ();
614
os << (uint32_t) *it;
615
it++;
616
for
(; it !=
m_nackedFrames
.end (); it++)
617
{
618
os <<
", "
<< (uint32_t) *it;
619
}
620
}
621
}
622
623
TypeId
624
UanHeaderRcAck::GetInstanceTypeId
(
void
)
const
625
{
626
return
GetTypeId
();
627
}
628
629
}
// namespace ns3
src
uan
model
uan-header-rc.cc
Generated on Tue Oct 9 2012 16:45:47 for ns-3 by
1.8.1.2