A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-header-rc.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "uan-header-rc.h"
10
11#include "ns3/mac8-address.h"
12
13#include <set>
14
15namespace ns3
16{
17
18NS_OBJECT_ENSURE_REGISTERED(UanHeaderRcData);
19NS_OBJECT_ENSURE_REGISTERED(UanHeaderRcRts);
20NS_OBJECT_ENSURE_REGISTERED(UanHeaderRcCtsGlobal);
21NS_OBJECT_ENSURE_REGISTERED(UanHeaderRcCts);
22NS_OBJECT_ENSURE_REGISTERED(UanHeaderRcAck);
23
25 : Header(),
26 m_frameNo(0),
27 m_propDelay(Seconds(0))
28{
29}
30
31UanHeaderRcData::UanHeaderRcData(uint8_t frameNo, Time propDelay)
32 : Header(),
33 m_frameNo(frameNo),
34 m_propDelay(propDelay)
35{
36}
37
41
44{
45 static TypeId tid = TypeId("ns3::UanHeaderRcData")
47 .SetGroupName("Uan")
48 .AddConstructor<UanHeaderRcData>();
49 return tid;
50}
51
52void
54{
55 m_frameNo = no;
56}
57
58void
60{
61 m_propDelay = propDelay;
62}
63
64uint8_t
66{
67 return m_frameNo;
68}
69
70Time
72{
73 return m_propDelay;
74}
75
78{
79 return 1 + 2;
80}
81
82void
84{
85 start.WriteU8(m_frameNo);
86 start.WriteU16((uint16_t)m_propDelay.RoundTo(Time::MS).GetMilliSeconds());
87}
88
91{
92 Buffer::Iterator rbuf = start;
93
94 m_frameNo = start.ReadU8();
95 m_propDelay = Seconds(((double)start.ReadU16()) / 1000.0);
96
97 return rbuf.GetDistanceFrom(start);
98}
99
100void
101UanHeaderRcData::Print(std::ostream& os, Time::Unit unit) const
102{
103 os << "Frame No=" << (uint32_t)m_frameNo << " Prop Delay=" << m_propDelay.As(unit);
104}
105
106void
107UanHeaderRcData::Print(std::ostream& os) const
108{
109 Print(os, Time::S);
110}
111
112TypeId
114{
115 return GetTypeId();
116}
117
119 : Header(),
120 m_frameNo(0),
121 m_noFrames(0),
122 m_length(0),
123 m_timeStamp(Seconds(0)),
124 m_retryNo(0)
125{
126}
127
129 uint8_t retryNo,
130 uint8_t noFrames,
131 uint16_t length,
132 Time timeStamp)
133 : Header(),
134 m_frameNo(frameNo),
135 m_noFrames(noFrames),
136 m_length(length),
137 m_timeStamp(timeStamp),
138 m_retryNo(retryNo)
139{
140}
141
145
146TypeId
148{
149 static TypeId tid = TypeId("ns3::UanHeaderRcRts")
150 .SetParent<Header>()
151 .SetGroupName("Uan")
152 .AddConstructor<UanHeaderRcRts>();
153 return tid;
154}
155
156void
158{
159 m_frameNo = no;
160}
161
162void
164{
165 m_noFrames = no;
166}
167
168void
170{
171 m_length = length;
172}
173
174void
176{
177 m_timeStamp = timeStamp;
178}
179
180void
182{
183 m_retryNo = no;
184}
185
186uint8_t
188{
189 return m_noFrames;
190}
191
192uint16_t
194{
195 return m_length;
196}
197
198Time
200{
201 return m_timeStamp;
202}
203
204uint8_t
206{
207 return m_retryNo;
208}
209
210uint8_t
212{
213 return m_frameNo;
214}
215
218{
219 return 1 + 1 + 1 + 4 + 2;
220}
221
222void
224{
225 start.WriteU8(m_frameNo);
226 start.WriteU8(m_retryNo);
227 start.WriteU8(m_noFrames);
228 start.WriteU16(m_length);
230}
231
234{
235 Buffer::Iterator rbuf = start;
236 m_frameNo = rbuf.ReadU8();
237 m_retryNo = rbuf.ReadU8();
238 m_noFrames = rbuf.ReadU8();
239 m_length = rbuf.ReadU16();
240 m_timeStamp = Seconds(((double)rbuf.ReadU32()) / 1000.0);
241 // m_timeStamp = Seconds ( rbuf.ReadU16 ()/1000 );
242 return rbuf.GetDistanceFrom(start);
243}
244
245void
246UanHeaderRcRts::Print(std::ostream& os, Time::Unit unit) const
247{
248 os << "Frame #=" << (uint32_t)m_frameNo << " Retry #=" << (uint32_t)m_retryNo
249 << " Num Frames=" << (uint32_t)m_noFrames << "Length=" << m_length
250 << " Time Stamp=" << m_timeStamp.As(unit);
251}
252
253void
254UanHeaderRcRts::Print(std::ostream& os) const
255{
256 Print(os, Time::S);
257}
258
259TypeId
261{
262 return GetTypeId();
263}
264
266 : Header(),
267 m_retryRate(0),
268 m_rateNum(0)
269{
270}
271
272UanHeaderRcCtsGlobal::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
284
285TypeId
287{
288 static TypeId tid = TypeId("ns3::UanHeaderRcCtsGlobal")
289 .SetParent<Header>()
290 .SetGroupName("Uan")
291 .AddConstructor<UanHeaderRcCtsGlobal>();
292 return tid;
293}
294
295void
297{
298 m_rateNum = rate;
299}
300
301void
303{
304 m_retryRate = rate;
305}
306
307void
312
313void
318
319Time
321{
322 return m_winTime;
323}
324
325Time
330
331uint16_t
336
337uint16_t
339{
340 return m_rateNum;
341}
342
345{
346 return 4 + 4 + 2 + 2;
347}
348
349void
351{
352 start.WriteU16(m_rateNum);
353 start.WriteU16(m_retryRate);
355 start.WriteU32((uint32_t)(m_winTime.RoundTo(Time::MS).GetMilliSeconds()));
356}
357
360{
361 Buffer::Iterator rbuf = start;
362 m_rateNum = rbuf.ReadU16();
363 m_retryRate = rbuf.ReadU16();
364 m_timeStampTx = Seconds(((double)rbuf.ReadU32()) / 1000.0);
365 m_winTime = Seconds(((double)rbuf.ReadU32()) / 1000.0);
366 return rbuf.GetDistanceFrom(start);
367}
368
369void
370UanHeaderRcCtsGlobal::Print(std::ostream& os, Time::Unit unit) const
371{
372 os << "CTS Global (Rate #=" << m_rateNum << ", Retry Rate=" << m_retryRate
373 << ", TX Time=" << m_timeStampTx.As(Time::S) << ", Win Time=" << m_winTime.As(Time::S)
374 << ")";
375}
376
377void
378UanHeaderRcCtsGlobal::Print(std::ostream& os) const
379{
380 Print(os, Time::S);
381}
382
383TypeId
388
390 : Header(),
391 m_frameNo(0),
392 m_timeStampRts(Seconds(0)),
393 m_retryNo(0),
394 m_delay(Seconds(0)),
395 m_address(Mac8Address::GetBroadcast())
396{
397}
398
400 uint8_t retryNo,
401 Time ts,
402 Time delay,
403 Mac8Address addr)
404 : Header(),
405 m_frameNo(frameNo),
406 m_timeStampRts(ts),
407 m_retryNo(retryNo),
408 m_delay(delay),
409 m_address(addr)
410{
411}
412
416
417TypeId
419{
420 static TypeId tid = TypeId("ns3::UanHeaderRcCts")
421 .SetParent<Header>()
422 .SetGroupName("Uan")
423 .AddConstructor<UanHeaderRcCts>();
424 return tid;
425}
426
427void
429{
430 m_frameNo = frameNo;
431}
432
433void
435{
436 m_timeStampRts = timeStamp;
437}
438
439void
441{
442 m_delay = delay;
443}
444
445void
447{
448 m_retryNo = no;
449}
450
451void
456
457uint8_t
459{
460 return m_frameNo;
461}
462
463Time
468
469Time
471{
472 return m_delay;
473}
474
475uint8_t
477{
478 return m_retryNo;
479}
480
483{
484 return m_address;
485}
486
489{
490 return 1 + 1 + 1 + 4 + 4;
491}
492
493void
495{
496 uint8_t address = 0;
497 m_address.CopyTo(&address);
498 start.WriteU8(address);
499 start.WriteU8(m_frameNo);
500 start.WriteU8(m_retryNo);
502 start.WriteU32((uint32_t)(m_delay.RoundTo(Time::MS).GetMilliSeconds()));
503}
504
507{
508 Buffer::Iterator rbuf = start;
509 m_address = Mac8Address(rbuf.ReadU8());
510 m_frameNo = rbuf.ReadU8();
511 m_retryNo = rbuf.ReadU8();
512 m_timeStampRts = Seconds(((double)rbuf.ReadU32()) / 1000.0);
513 m_delay = Seconds(((double)rbuf.ReadU32()) / 1000.0);
514
515 return rbuf.GetDistanceFrom(start);
516}
517
518void
519UanHeaderRcCts::Print(std::ostream& os, Time::Unit unit) const
520{
521 os << "CTS (Addr=" << m_address << " Frame #=" << (uint32_t)m_frameNo
522 << " Retry #=" << (uint32_t)m_retryNo << " RTS Rx Timestamp=" << m_timeStampRts.As(unit)
523 << " Delay until TX=" << m_delay.As(unit) << ")";
524}
525
526void
527UanHeaderRcCts::Print(std::ostream& os) const
528{
529 Print(os, Time::S);
530}
531
532TypeId
534{
535 return GetTypeId();
536}
537
539 : m_frameNo(0)
540{
541}
542
547
548TypeId
550{
551 static TypeId tid = TypeId("ns3::UanHeaderRcAck")
552 .SetParent<Header>()
553 .SetGroupName("Uan")
554 .AddConstructor<UanHeaderRcAck>();
555 return tid;
556}
557
558void
560{
561 m_frameNo = noFrames;
562}
563
564void
566{
567 m_nackedFrames.insert(frame);
568}
569
570const std::set<uint8_t>&
575
576uint8_t
578{
579 return m_frameNo;
580}
581
582uint8_t
584{
585 return static_cast<uint8_t>(m_nackedFrames.size());
586}
587
590{
591 return 1 + 1 + GetNoNacks();
592}
593
594void
596{
597 start.WriteU8(m_frameNo);
598 start.WriteU8(GetNoNacks());
599 auto it = m_nackedFrames.begin();
600 for (; it != m_nackedFrames.end(); it++)
601 {
602 start.WriteU8(*it);
603 }
604}
605
608{
609 Buffer::Iterator rbuf = start;
610 m_frameNo = rbuf.ReadU8();
611 uint8_t noAcks = rbuf.ReadU8();
612 m_nackedFrames.clear();
613 for (uint32_t i = 0; i < noAcks; i++)
614 {
615 m_nackedFrames.insert(rbuf.ReadU8());
616 }
617 return rbuf.GetDistanceFrom(start);
618}
619
620void
621UanHeaderRcAck::Print(std::ostream& os) const
622{
623 os << "# Frames=" << (uint32_t)m_frameNo << " # nacked=" << (uint32_t)GetNoNacks()
624 << " Nacked: ";
625 if (GetNoNacks() > 0)
626 {
627 auto it = m_nackedFrames.begin();
628 os << (uint32_t)*it;
629 it++;
630 for (; it != m_nackedFrames.end(); it++)
631 {
632 os << ", " << (uint32_t)*it;
633 }
634 }
635}
636
637TypeId
639{
640 return GetTypeId();
641}
642
643} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
uint32_t ReadU32()
Definition buffer.cc:955
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint16_t ReadU16()
Definition buffer.h:1024
Protocol header serialization and deserialization.
Definition header.h:33
A class used for addressing MAC8 MAC's.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
@ MS
millisecond
Definition nstime.h:106
@ S
second
Definition nstime.h:105
Time RoundTo(Unit unit) const
Round a Time to a specific unit.
Definition nstime.h:593
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Header used for ACK packets by protocol UanMacRc.
static TypeId GetTypeId()
Register this type.
uint8_t m_frameNo
Next frame number.
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
std::set< uint8_t > m_nackedFrames
Marker for nacked frames.
const std::set< uint8_t > & GetNackedFrames() const
Get the set of NACK'ed frames.
~UanHeaderRcAck() override
Destructor.
void Serialize(Buffer::Iterator start) const override
UanHeaderRcAck()
Default constructor.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetFrameNo() const
Get the reservation frame number being ACKed.
void AddNackedFrame(uint8_t frame)
NACK a frame.
void Print(std::ostream &os) const override
uint8_t GetNoNacks() const
Get the number of data frames being NACKed.
void SetFrameNo(uint8_t frameNo)
Set the frame number of the reservation being acknowledged.
Cycle broadcast information.
void Print(std::ostream &os, Time::Unit unit) const
Specialized Print with Time::Unit declared.
uint32_t Deserialize(Buffer::Iterator start) override
UanHeaderRcCtsGlobal()
Default constructor.
static TypeId GetTypeId()
Register this type.
void Serialize(Buffer::Iterator start) const override
void SetRateNum(uint16_t rate)
Set the rate number corresponding to data rate of current cycle.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
~UanHeaderRcCtsGlobal() override
Destructor.
void SetRetryRate(uint16_t rate)
Set the retry rate number for the current cycle.
void SetTxTimeStamp(Time timeStamp)
Set the CTS timestamp.
Time m_winTime
Window time.
uint16_t GetRetryRate() const
Get the retry rate number.
uint16_t m_retryRate
Retry rate.
Time GetTxTimeStamp() const
Get the CTS transmit timestamp.
uint16_t m_rateNum
Rate number.
Time GetWindowTime() const
Get the window time (time duration following blocking time to allow RTS transmissions).
void SetWindowTime(Time t)
Set the window time (time duration following blocking time to allow RTS transmissions).
uint16_t GetRateNum() const
Get the data rate number.
uint32_t GetSerializedSize() const override
Time GetDelayToTx() const
Get the time delay from TX time of CTS packet until arrival of first data frame.
uint8_t GetFrameNo() const
Get the frame number of the RTS being cleared.
uint32_t Deserialize(Buffer::Iterator start) override
void SetRtsTimeStamp(Time timeStamp)
Set the timestamp for RTS reception.
UanHeaderRcCts()
Default constructor.
void SetFrameNo(uint8_t frameNo)
Set the RTS frame number being cleared.
uint32_t GetSerializedSize() const override
~UanHeaderRcCts() override
Destructor.
void SetDelayToTx(Time delay)
Set the time delay from CTS transmission to first data frame arrival.
void Serialize(Buffer::Iterator start) const override
Mac8Address m_address
Destination of CTS packet.
uint8_t GetRetryNo() const
Get the retry number of the RTS packet being cleared.
Mac8Address GetAddress() const
Get the destination address, for scheduling info.
Time m_delay
Delay until transmission.
Time m_timeStampRts
RX time of RTS packet at gateway.
void Print(std::ostream &os, Time::Unit unit) const
Specialized Print with Time::Unit declared.
uint8_t m_frameNo
Reservation frame number being cleared.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetRetryNo(uint8_t no)
Set the retry number of the RTS frame being cleared.
static TypeId GetTypeId()
Register this type.
Time GetRtsTimeStamp() const
Get the receive time of the RTS being cleared.
void SetAddress(Mac8Address addr)
Set the destination address, for scheduling info.
uint8_t m_retryNo
Retry number of received RTS packet.
Extra data header information.
Time m_propDelay
Propagation delay.
~UanHeaderRcData() override
Destructor.
uint8_t m_frameNo
Data frame number.
void SetFrameNo(uint8_t frameNum)
Set the frame number of the reservation being transmitted.
UanHeaderRcData()
Default constructor.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetFrameNo() const
Get the frame number of the reservation being transmitted.
static TypeId GetTypeId()
Register this type.
uint32_t GetSerializedSize() const override
void Serialize(Buffer::Iterator start) const override
void SetPropDelay(Time propDelay)
Set the propagation delay as found in handshaking.
Time GetPropDelay() const
Get the propagation delay found in handshaking.
uint32_t Deserialize(Buffer::Iterator start) override
void Print(std::ostream &os, Time::Unit unit) const
Specialized Print with Time::Unit declared.
uint16_t m_length
Number of bytes (including headers) in data.
void Print(std::ostream &os, Time::Unit unit) const
Specialized Print with Time::Unit declared.
UanHeaderRcRts()
Default constructor.
uint8_t GetFrameNo() const
Get the frame number.
uint16_t GetLength() const
Get the total number of bytes in the reservation, including headers.
uint8_t m_retryNo
Retry number of RTS packet.
uint8_t GetNoFrames() const
Get the number of data frames in the reservation.
void SetFrameNo(uint8_t fno)
Set the frame number.
void SetTimeStamp(Time timeStamp)
Set RTS transmission time.
static TypeId GetTypeId()
Register this type.
uint8_t m_noFrames
Number of data frames in reservation.
Time GetTimeStamp() const
Get the transmit timestamp of this RTS packet.
~UanHeaderRcRts() override
Destructor.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetRetryNo(uint8_t no)
Set the retry number of this RTS packet.
uint32_t GetSerializedSize() const override
uint8_t m_frameNo
Reservation frame number.
void Serialize(Buffer::Iterator start) const override
uint8_t GetRetryNo() const
Get the retry number of this RTS packet.
void SetNoFrames(uint8_t no)
Set the number of data frames included in this reservation request.
void SetLength(uint16_t length)
Set the number of data bytes in the reservation.
Time m_timeStamp
RTS TX timestamp.
uint32_t Deserialize(Buffer::Iterator start) override
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.