A Discrete-Event Network Simulator
API
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 #include "ns3/mac8-address.h"
24 
25 #include <set>
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcData);
30 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcRts);
31 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcCtsGlobal);
32 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcCts);
33 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcAck);
34 
36  : Header (),
37  m_frameNo (0),
38  m_propDelay (Seconds (0))
39 {
40 }
41 
42 UanHeaderRcData::UanHeaderRcData (uint8_t frameNo, Time propDelay)
43  : Header (),
44  m_frameNo (frameNo),
45  m_propDelay (propDelay)
46 {
47 
48 }
49 
51 {
52 }
53 
54 TypeId
56 {
57  static TypeId tid = TypeId ("ns3::UanHeaderRcData")
58  .SetParent<Header> ()
59  .SetGroupName ("Uan")
60  .AddConstructor<UanHeaderRcData> ()
61  ;
62  return tid;
63 }
64 
65 void
67 {
68  m_frameNo = no;
69 }
70 
71 void
73 {
74  m_propDelay = propDelay;
75 }
76 
77 uint8_t
79 {
80  return m_frameNo;
81 }
82 
83 Time
85 {
86  return m_propDelay;
87 }
88 
89 uint32_t
91 {
92  return 1 + 2;
93 }
94 
95 void
97 {
98  start.WriteU8 (m_frameNo);
99  start.WriteU16 ( (uint16_t)(1000.0 * m_propDelay.GetSeconds () + 0.5));
100 }
101 uint32_t
103 {
104  Buffer::Iterator rbuf = start;
105 
106  m_frameNo = start.ReadU8 ();
107  m_propDelay = Seconds ( ((double) start.ReadU16 ()) / 1000.0 );
108 
109  return rbuf.GetDistanceFrom (start);
110 }
111 
112 void
113 UanHeaderRcData::Print (std::ostream &os) const
114 {
115  os << "Frame No=" << (uint32_t) m_frameNo << " Prop Delay=" << m_propDelay.GetSeconds ();
116 }
117 
118 TypeId
120 {
121  return GetTypeId ();
122 }
123 
124 
126  : Header (),
127  m_frameNo (0),
128  m_noFrames (0),
129  m_length (0),
130  m_timeStamp (Seconds (0)),
131  m_retryNo (0)
132 {
133 
134 }
135 
136 UanHeaderRcRts::UanHeaderRcRts (uint8_t frameNo, uint8_t retryNo, uint8_t noFrames, uint16_t length, Time timeStamp)
137  : Header (),
138  m_frameNo (frameNo),
139  m_noFrames (noFrames),
140  m_length (length),
141  m_timeStamp (timeStamp),
142  m_retryNo (retryNo)
143 {
144 
145 }
146 
148 {
149 
150 }
151 
152 TypeId
154 {
155  static TypeId tid = TypeId ("ns3::UanHeaderRcRts")
156  .SetParent<Header> ()
157  .SetGroupName ("Uan")
158  .AddConstructor<UanHeaderRcRts> ()
159  ;
160  return tid;
161 
162 }
163 
164 void
166 {
167  m_frameNo = no;
168 }
169 
170 void
172 {
173  m_noFrames = no;
174 }
175 
176 void
177 UanHeaderRcRts::SetLength (uint16_t length)
178 {
179  m_length = length;
180 }
181 void
183 {
184  m_timeStamp = timeStamp;
185 }
186 
187 void
189 {
190  m_retryNo = no;
191 }
192 uint8_t
194 {
195  return m_noFrames;
196 }
197 
198 uint16_t
200 {
201  return m_length;
202 }
203 
204 Time
206 {
207  return m_timeStamp;
208 }
209 
210 uint8_t
212 {
213  return m_retryNo;
214 }
215 
216 uint8_t
218 {
219  return m_frameNo;
220 }
221 
222 uint32_t
224 {
225  return 1 + 1 + 1 + 4 + 2;
226 }
227 
228 void
230 {
231  start.WriteU8 (m_frameNo);
232  start.WriteU8 (m_retryNo);
233  start.WriteU8 (m_noFrames);
234  start.WriteU16 (m_length);
235  start.WriteU32 ((uint32_t)(m_timeStamp.GetSeconds () * 1000.0 + 0.5));
236  // start.WriteU16(uint16_t (m_timeStamp.GetSeconds ()*1000));
237 }
238 
239 uint32_t
241 {
242  Buffer::Iterator rbuf = start;
243  m_frameNo = rbuf.ReadU8 ();
244  m_retryNo = rbuf.ReadU8 ();
245  m_noFrames = rbuf.ReadU8 ();
246  m_length = rbuf.ReadU16 ();
247  m_timeStamp = Seconds ( ((double) rbuf.ReadU32 ()) / 1000.0 );
248  // m_timeStamp = Seconds ( rbuf.ReadU16 ()/1000 );
249  return rbuf.GetDistanceFrom (start);
250 }
251 
252 void
253 UanHeaderRcRts::Print (std::ostream &os) const
254 {
255  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 ();
256 }
257 
258 TypeId
260 {
261  return GetTypeId ();
262 }
263 
264 
265 
266 
268  : Header (),
269  m_retryRate (0),
270  m_rateNum (0)
271 {
272 
273 }
274 
275 UanHeaderRcCtsGlobal::UanHeaderRcCtsGlobal (Time wt, Time ts, uint16_t rate, uint16_t retryRate)
276  : Header (),
277  m_timeStampTx (ts),
278  m_winTime (wt),
279  m_retryRate (retryRate),
280  m_rateNum (rate)
281 {
282 
283 }
284 
286 {
287 
288 }
289 
290 TypeId
292 {
293  static TypeId tid = TypeId ("ns3::UanHeaderRcCtsGlobal")
294  .SetParent<Header> ()
295  .SetGroupName ("Uan")
296  .AddConstructor<UanHeaderRcCtsGlobal> ()
297  ;
298  return tid;
299 
300 }
301 
302 
303 void
305 {
306  m_rateNum = rate;
307 }
308 
309 void
311 {
312  m_retryRate = rate;
313 }
314 
315 void
317 {
318  m_winTime = t;
319 }
320 
321 void
323 {
324  m_timeStampTx = t;
325 }
326 
327 Time
329 {
330  return m_winTime;
331 }
332 
333 Time
335 {
336  return m_timeStampTx;
337 }
338 
339 uint16_t
341 {
342  return m_retryRate;
343 }
344 
345 uint16_t
347 {
348  return m_rateNum;
349 }
350 uint32_t
352 {
353  return 4 + 4 + 2 + 2;
354 }
355 
356 void
358 {
359  start.WriteU16 (m_rateNum);
360  start.WriteU16 (m_retryRate);
361  start.WriteU32 ( (uint32_t)(m_timeStampTx.GetSeconds () * 1000.0 + 0.5));
362  start.WriteU32 ( (uint32_t)(m_winTime.GetSeconds () * 1000.0 + 0.5));
363 }
364 
365 uint32_t
367 {
368  Buffer::Iterator rbuf = start;
369  m_rateNum = rbuf.ReadU16 ();
370  m_retryRate = rbuf.ReadU16 ();
371  m_timeStampTx = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
372  m_winTime = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
373  return rbuf.GetDistanceFrom (start);
374 
375 }
376 
377 void
378 UanHeaderRcCtsGlobal::Print (std::ostream &os) const
379 {
380  os << "CTS Global (Rate #=" << m_rateNum << ", Retry Rate=" << m_retryRate << ", TX Time=" << m_timeStampTx.GetSeconds () << ", Win Time=" << m_winTime.GetSeconds () << ")";
381 }
382 
383 TypeId
385 {
386  return GetTypeId ();
387 }
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 }
399 
400 UanHeaderRcCts::UanHeaderRcCts (uint8_t frameNo, uint8_t retryNo, Time ts, Time delay, Mac8Address addr)
401  : Header (),
402  m_frameNo (frameNo),
403  m_timeStampRts (ts),
404  m_retryNo (retryNo),
405  m_delay (delay),
406  m_address (addr)
407 {
408 
409 }
410 
412 {
413 
414 }
415 
416 TypeId
418 {
419  static TypeId tid = TypeId ("ns3::UanHeaderRcCts")
420  .SetParent<Header> ()
421  .SetGroupName ("Uan")
422  .AddConstructor<UanHeaderRcCts> ()
423  ;
424  return tid;
425 
426 }
427 
428 void
429 UanHeaderRcCts::SetFrameNo (uint8_t frameNo)
430 {
431  m_frameNo = frameNo;
432 }
433 
434 void
436 {
437  m_timeStampRts = timeStamp;
438 }
439 
440 
441 void
443 {
444  m_delay = delay;
445 }
446 
447 void
449 {
450  m_retryNo = no;
451 }
452 
453 void
455 {
456  m_address = addr;
457 }
458 uint8_t
460 {
461  return m_frameNo;
462 }
463 
464 Time
466 {
467  return m_timeStampRts;
468 }
469 
470 Time
472 {
473  return m_delay;
474 }
475 
476 uint8_t
478 {
479  return m_retryNo;
480 }
481 
484 {
485  return m_address;
486 }
487 
488 uint32_t
490 {
491  return 1 + 1 + 1 + 4 + 4;
492 }
493 
494 
495 void
497 {
498  uint8_t address = 0;
500  start.WriteU8 (address);
501  start.WriteU8 (m_frameNo);
502  start.WriteU8 (m_retryNo);
503  start.WriteU32 ((uint32_t)(m_timeStampRts.GetSeconds () * 1000.0 + 0.5));
504  start.WriteU32 ((uint32_t)(m_delay.GetSeconds () * 1000.0 + 0.5));
505 }
506 
507 uint32_t
509 {
510  Buffer::Iterator rbuf = start;
511  m_address = Mac8Address (rbuf.ReadU8 ());
512  m_frameNo = rbuf.ReadU8 ();
513  m_retryNo = rbuf.ReadU8 ();
514  m_timeStampRts = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
515  m_delay = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
516 
517  return rbuf.GetDistanceFrom (start);
518 }
519 
520 void
521 UanHeaderRcCts::Print (std::ostream &os) const
522 {
523  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 () << ")";
524 }
525 
526 TypeId
528 {
529  return GetTypeId ();
530 }
531 
533  : m_frameNo (0)
534 {
535 }
536 
538 {
539  m_nackedFrames.clear ();
540 }
541 
542 TypeId
544 {
545  static TypeId tid = TypeId ("ns3::UanHeaderRcAck")
546  .SetParent<Header> ()
547  .SetGroupName ("Uan")
548  .AddConstructor<UanHeaderRcAck> ()
549  ;
550  return tid;
551 }
552 
553 void
554 UanHeaderRcAck::SetFrameNo (uint8_t noFrames)
555 {
556  m_frameNo = noFrames;
557 }
558 
559 void
561 {
562  m_nackedFrames.insert (frame);
563 }
564 
565 const std::set<uint8_t> &
567 {
568  return m_nackedFrames;
569 }
570 
571 uint8_t
573 {
574  return m_frameNo;
575 }
576 
577 uint8_t
579 {
580  return static_cast<uint8_t> (m_nackedFrames.size ());
581 }
582 
583 uint32_t
585 {
586  return 1 + 1 + GetNoNacks ();
587 }
588 
589 void
591 {
592  start.WriteU8 (m_frameNo);
593  start.WriteU8 (GetNoNacks ());
594  std::set<uint8_t>::iterator it = m_nackedFrames.begin ();
595  for (; it != m_nackedFrames.end (); it++)
596  {
597  start.WriteU8 (*it);
598  }
599 }
600 
601 uint32_t
603 {
604  Buffer::Iterator rbuf = start;
605  m_frameNo = rbuf.ReadU8 ();
606  uint8_t noAcks = rbuf.ReadU8 ();
607  m_nackedFrames.clear ();
608  for (uint32_t i = 0; i < noAcks; i++)
609  {
610  m_nackedFrames.insert (rbuf.ReadU8 ());
611  }
612  return rbuf.GetDistanceFrom (start);
613 }
614 
615 void
616 UanHeaderRcAck::Print (std::ostream &os) const
617 {
618  os << "# Frames=" << (uint32_t) m_frameNo << " # nacked=" << (uint32_t) GetNoNacks () << " Nacked: ";
619  if (GetNoNacks () > 0)
620  {
621  std::set<uint8_t>::iterator it = m_nackedFrames.begin ();
622  os << (uint32_t) *it;
623  it++;
624  for (; it != m_nackedFrames.end (); it++)
625  {
626  os << ", " << (uint32_t) *it;
627  }
628  }
629 }
630 
631 TypeId
633 {
634  return GetTypeId ();
635 }
636 
637 } // namespace ns3
uint16_t ReadU16(void)
Definition: buffer.h:1029
Protocol header serialization and deserialization.
Definition: header.h:42
virtual uint32_t Deserialize(Buffer::Iterator start)
void SetNoFrames(uint8_t no)
Set the number of data frames included in this reservation request.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint8_t GetRetryNo(void) const
Get the retry number of the RTS packet being cleared.
uint32_t ReadU32(void)
Definition: buffer.cc:972
static TypeId GetTypeId(void)
Register this type.
void SetPropDelay(Time propDelay)
Set the propagation delay as found in handshaking.
Cycle broadcast information.
virtual void Print(std::ostream &os) const
void SetRateNum(uint16_t rate)
Set the rate number corresponding to data rate of current cycle.
UanHeaderRcCtsGlobal()
Default constructor.
void SetRetryNo(uint8_t no)
Set the retry number of the RTS frame being cleared.
void SetFrameNo(uint8_t frameNum)
Set the frame number of the reservation being transmitted.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual void Serialize(Buffer::Iterator start) const
uint8_t GetFrameNo(void) const
Get the reservation frame number being ACKed.
Header used for ACK packets by protocol UanMacRc.
virtual uint32_t Deserialize(Buffer::Iterator start)
uint8_t m_frameNo
Reservation frame number.
def start()
Definition: core.py:1844
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
virtual uint32_t GetSerializedSize(void) const
virtual uint32_t GetSerializedSize(void) const
uint16_t m_rateNum
Rate number.
Time m_winTime
Window time.
uint8_t m_frameNo
Next frame number.
Time GetWindowTime(void) const
Get the window time (time duration following blocking time to allow RTS transmissions).
Time GetPropDelay(void) const
Get the propagation delay found in handshaking.
uint16_t m_length
Number of bytes (including headers) in data.
void SetWindowTime(Time t)
Set the window time (time duration following blocking time to allow RTS transmissions).
iterator in a Buffer instance
Definition: buffer.h:98
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
virtual void Print(std::ostream &os) const
virtual uint32_t GetSerializedSize(void) const
Time GetTimeStamp(void) const
Get the transmit timestamp of this RTS packet.
uint16_t GetRetryRate(void) const
Get the retry rate number.
virtual void Print(std::ostream &os) const
std::set< uint8_t > m_nackedFrames
Marker for nacked frames.
uint8_t m_retryNo
Retry number of received RTS packet.
void SetAddress(Mac8Address addr)
Set the destination address, for scheduling info.
uint8_t GetFrameNo(void) const
Get the frame number of the reservation being transmitted.
A class used for addressing MAC8 MAC&#39;s.
Definition: mac8-address.h:42
virtual uint32_t Deserialize(Buffer::Iterator start)
void AddNackedFrame(uint8_t frame)
NACK a frame.
virtual void Serialize(Buffer::Iterator start) const
virtual uint32_t Deserialize(Buffer::Iterator start)
Time m_delay
Delay until transmission.
uint8_t GetNoFrames(void) const
Get the number of data frames in the reservation.
uint8_t GetFrameNo(void) const
Get the frame number.
void SetLength(uint16_t length)
Set the number of data bytes in the reservation.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetTimeStamp(Time timeStamp)
Set RTS transmission time.
Time m_timeStampRts
RX time of RTS packet at gateway.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Register this type.
address
Definition: first.py:37
void SetDelayToTx(Time delay)
Set the time delay from CTS transmission to first data frame arrival.
virtual ~UanHeaderRcAck()
Destructor.
void SetFrameNo(uint8_t frameNo)
Set the RTS frame number being cleared.
Time m_timeStampTx
Timestamp.
Time GetTxTimeStamp(void) const
Get the CTS transmit timestamp.
virtual ~UanHeaderRcCts()
Destructor.
virtual void Serialize(Buffer::Iterator start) const
void SetTxTimeStamp(Time timeStamp)
Set the CTS timestamp.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetRtsTimeStamp(Time timeStamp)
Set the timestamp for RTS reception.
const std::set< uint8_t > & GetNackedFrames(void) const
Get the set of NACK&#39;ed frames.
static TypeId GetTypeId(void)
Register this type.
uint8_t m_frameNo
Data frame number.
Definition: uan-header-rc.h:98
UanHeaderRcData()
Default constructor.
uint8_t GetRetryNo(void) const
Get the retry number of this RTS packet.
uint16_t m_retryRate
Retry rate.
virtual uint32_t Deserialize(Buffer::Iterator start)
Time m_propDelay
Propagation delay.
Definition: uan-header-rc.h:99
virtual void Print(std::ostream &os) const
virtual ~UanHeaderRcRts()
Destructor.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SetFrameNo(uint8_t frameNo)
Set the frame number of the reservation being acknowledged.
virtual void Print(std::ostream &os) const
virtual void Serialize(Buffer::Iterator start) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
UanHeaderRcCts()
Default constructor.
uint8_t ReadU8(void)
Definition: buffer.h:1021
Mac8Address m_address
Destination of CTS packet.
uint16_t GetLength(void) const
Get the total number of bytes in the reservation, including headers.
static TypeId GetTypeId(void)
Register this type.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetRetryRate(uint16_t rate)
Set the retry rate number for the current cycle.
UanHeaderRcRts()
Default constructor.
uint8_t m_retryNo
Retry number of RTS packet.
~UanHeaderRcCtsGlobal()
Destructor.
virtual void Serialize(Buffer::Iterator start) const
virtual uint32_t GetSerializedSize(void) const
uint8_t m_frameNo
Reservation frame number being cleared.
uint16_t GetRateNum(void) const
Get the data rate number.
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t GetNoNacks(void) const
Get the number of data frames being NACKed.
Time m_timeStamp
RTS TX timestamp.
static TypeId GetTypeId(void)
Register this type.
uint8_t GetFrameNo(void) const
Get the frame number of the RTS being cleared.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetRetryNo(uint8_t no)
Set the retry number of this RTS packet.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Mac8Address GetAddress(void) const
Get the destination address, for scheduling info.
Time GetDelayToTx(void) const
Get the time delay from TX time of CTS packet until arrival of first data frame.
virtual uint32_t GetSerializedSize(void) const
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:80
uint8_t m_noFrames
Number of data frames in reservation.
Extra data header information.
Definition: uan-header-rc.h:41
UanHeaderRcAck()
Default constructor.
Time GetRtsTimeStamp(void) const
Get the receive time of the RTS being cleared.
void SetFrameNo(uint8_t fno)
Set the frame number.
virtual ~UanHeaderRcData()
Destructor.