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 
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 
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 
50 {
51 }
52 
53 TypeId
55 {
56  static TypeId tid = TypeId ("ns3::UanHeaderRcData")
57  .SetParent<Header> ()
58  .SetGroupName ("Uan")
59  .AddConstructor<UanHeaderRcData> ()
60  ;
61  return tid;
62 }
63 
64 void
66 {
67  m_frameNo = no;
68 }
69 
70 void
72 {
73  m_propDelay = propDelay;
74 }
75 
76 uint8_t
78 {
79  return m_frameNo;
80 }
81 
82 Time
84 {
85  return m_propDelay;
86 }
87 
88 uint32_t
90 {
91  return 1 + 2;
92 }
93 
94 void
96 {
97  start.WriteU8 (m_frameNo);
98  start.WriteU16 ( (uint16_t)(1000.0 * m_propDelay.GetSeconds () + 0.5));
99 }
100 uint32_t
102 {
103  Buffer::Iterator rbuf = start;
104 
105  m_frameNo = start.ReadU8 ();
106  m_propDelay = Seconds ( ((double) start.ReadU16 ()) / 1000.0 );
107 
108  return rbuf.GetDistanceFrom (start);
109 }
110 
111 void
112 UanHeaderRcData::Print (std::ostream &os) const
113 {
114  os << "Frame No=" << (uint32_t) m_frameNo << " Prop Delay=" << m_propDelay.GetSeconds ();
115 }
116 
117 TypeId
119 {
120  return GetTypeId ();
121 }
122 
123 
125  : Header (),
126  m_frameNo (0),
127  m_noFrames (0),
128  m_length (0),
129  m_timeStamp (Seconds (0)),
130  m_retryNo (0)
131 {
132 
133 }
134 
135 UanHeaderRcRts::UanHeaderRcRts (uint8_t frameNo, uint8_t retryNo, uint8_t noFrames, uint16_t length, Time timeStamp)
136  : Header (),
137  m_frameNo (frameNo),
138  m_noFrames (noFrames),
139  m_length (length),
140  m_timeStamp (timeStamp),
141  m_retryNo (retryNo)
142 {
143 
144 }
145 
147 {
148 
149 }
150 
151 TypeId
153 {
154  static TypeId tid = TypeId ("ns3::UanHeaderRcRts")
155  .SetParent<Header> ()
156  .SetGroupName ("Uan")
157  .AddConstructor<UanHeaderRcRts> ()
158  ;
159  return tid;
160 
161 }
162 
163 void
165 {
166  m_frameNo = no;
167 }
168 
169 void
171 {
172  m_noFrames = no;
173 }
174 
175 void
176 UanHeaderRcRts::SetLength (uint16_t length)
177 {
178  m_length = length;
179 }
180 void
182 {
183  m_timeStamp = timeStamp;
184 }
185 
186 void
188 {
189  m_retryNo = no;
190 }
191 uint8_t
193 {
194  return m_noFrames;
195 }
196 
197 uint16_t
199 {
200  return m_length;
201 }
202 
203 Time
205 {
206  return m_timeStamp;
207 }
208 
209 uint8_t
211 {
212  return m_retryNo;
213 }
214 
215 uint8_t
217 {
218  return m_frameNo;
219 }
220 
221 uint32_t
223 {
224  return 1 + 1 + 1 + 4 + 2;
225 }
226 
227 void
229 {
230  start.WriteU8 (m_frameNo);
231  start.WriteU8 (m_retryNo);
232  start.WriteU8 (m_noFrames);
233  start.WriteU16 (m_length);
234  start.WriteU32 ((uint32_t)(m_timeStamp.GetSeconds () * 1000.0 + 0.5));
235  // start.WriteU16(uint16_t (m_timeStamp.GetSeconds ()*1000));
236 }
237 
238 uint32_t
240 {
241  Buffer::Iterator rbuf = start;
242  m_frameNo = rbuf.ReadU8 ();
243  m_retryNo = rbuf.ReadU8 ();
244  m_noFrames = rbuf.ReadU8 ();
245  m_length = rbuf.ReadU16 ();
246  m_timeStamp = Seconds ( ((double) rbuf.ReadU32 ()) / 1000.0 );
247  // m_timeStamp = Seconds ( rbuf.ReadU16 ()/1000 );
248  return rbuf.GetDistanceFrom (start);
249 }
250 
251 void
252 UanHeaderRcRts::Print (std::ostream &os) const
253 {
254  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 ();
255 }
256 
257 TypeId
259 {
260  return GetTypeId ();
261 }
262 
263 
264 
265 
267  : Header (),
268  m_retryRate (0),
269  m_rateNum (0)
270 {
271 
272 }
273 
274 UanHeaderRcCtsGlobal::UanHeaderRcCtsGlobal (Time wt, Time ts, uint16_t rate, uint16_t retryRate)
275  : Header (),
276  m_timeStampTx (ts),
277  m_winTime (wt),
278  m_retryRate (retryRate),
279  m_rateNum (rate)
280 {
281 
282 }
283 
285 {
286 
287 }
288 
289 TypeId
291 {
292  static TypeId tid = TypeId ("ns3::UanHeaderRcCtsGlobal")
293  .SetParent<Header> ()
294  .SetGroupName ("Uan")
295  .AddConstructor<UanHeaderRcCtsGlobal> ()
296  ;
297  return tid;
298 
299 }
300 
301 
302 void
304 {
305  m_rateNum = rate;
306 }
307 
308 void
310 {
311  m_retryRate = rate;
312 }
313 
314 void
316 {
317  m_winTime = t;
318 }
319 
320 void
322 {
323  m_timeStampTx = t;
324 }
325 
326 Time
328 {
329  return m_winTime;
330 }
331 
332 Time
334 {
335  return m_timeStampTx;
336 }
337 
338 uint16_t
340 {
341  return m_retryRate;
342 }
343 
344 uint16_t
346 {
347  return m_rateNum;
348 }
349 uint32_t
351 {
352  return 4 + 4 + 2 + 2;
353 }
354 
355 void
357 {
358  start.WriteU16 (m_rateNum);
359  start.WriteU16 (m_retryRate);
360  start.WriteU32 ( (uint32_t)(m_timeStampTx.GetSeconds () * 1000.0 + 0.5));
361  start.WriteU32 ( (uint32_t)(m_winTime.GetSeconds () * 1000.0 + 0.5));
362 }
363 
364 uint32_t
366 {
367  Buffer::Iterator rbuf = start;
368  m_rateNum = rbuf.ReadU16 ();
369  m_retryRate = rbuf.ReadU16 ();
370  m_timeStampTx = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
371  m_winTime = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
372  return rbuf.GetDistanceFrom (start);
373 
374 }
375 
376 void
377 UanHeaderRcCtsGlobal::Print (std::ostream &os) const
378 {
379  os << "CTS Global (Rate #=" << m_rateNum << ", Retry Rate=" << m_retryRate << ", TX Time=" << m_timeStampTx.GetSeconds () << ", Win Time=" << m_winTime.GetSeconds () << ")";
380 }
381 
382 TypeId
384 {
385  return GetTypeId ();
386 }
387 
389  : Header (),
390  m_frameNo (0),
391  m_timeStampRts (Seconds (0)),
392  m_retryNo (0),
393  m_delay (Seconds (0)),
394  m_address (UanAddress::GetBroadcast ())
395 {
396 
397 }
398 
399 UanHeaderRcCts::UanHeaderRcCts (uint8_t frameNo, uint8_t retryNo, Time ts, Time delay, UanAddress addr)
400  : Header (),
401  m_frameNo (frameNo),
402  m_timeStampRts (ts),
403  m_retryNo (retryNo),
404  m_delay (delay),
405  m_address (addr)
406 {
407 
408 }
409 
411 {
412 
413 }
414 
415 TypeId
417 {
418  static TypeId tid = TypeId ("ns3::UanHeaderRcCts")
419  .SetParent<Header> ()
420  .SetGroupName ("Uan")
421  .AddConstructor<UanHeaderRcCts> ()
422  ;
423  return tid;
424 
425 }
426 
427 void
428 UanHeaderRcCts::SetFrameNo (uint8_t frameNo)
429 {
430  m_frameNo = frameNo;
431 }
432 
433 void
435 {
436  m_timeStampRts = timeStamp;
437 }
438 
439 
440 void
442 {
443  m_delay = delay;
444 }
445 
446 void
448 {
449  m_retryNo = no;
450 }
451 
452 void
454 {
455  m_address = addr;
456 }
457 uint8_t
459 {
460  return m_frameNo;
461 }
462 
463 Time
465 {
466  return m_timeStampRts;
467 }
468 
469 Time
471 {
472  return m_delay;
473 }
474 
475 uint8_t
477 {
478  return m_retryNo;
479 }
480 
483 {
484  return m_address;
485 }
486 
487 uint32_t
489 {
490  return 1 + 1 + 1 + 4 + 4;
491 }
492 
493 
494 void
496 {
497  start.WriteU8 (m_address.GetAsInt ());
498  start.WriteU8 (m_frameNo);
499  start.WriteU8 (m_retryNo);
500  start.WriteU32 ((uint32_t)(m_timeStampRts.GetSeconds () * 1000.0 + 0.5));
501  start.WriteU32 ((uint32_t)(m_delay.GetSeconds () * 1000.0 + 0.5));
502 }
503 
504 uint32_t
506 {
507  Buffer::Iterator rbuf = start;
508  m_address = UanAddress (rbuf.ReadU8 ());
509  m_frameNo = rbuf.ReadU8 ();
510  m_retryNo = rbuf.ReadU8 ();
511  m_timeStampRts = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
512  m_delay = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
513 
514  return rbuf.GetDistanceFrom (start);
515 }
516 
517 void
518 UanHeaderRcCts::Print (std::ostream &os) const
519 {
520  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 () << ")";
521 }
522 
523 TypeId
525 {
526  return GetTypeId ();
527 }
528 
530  : m_frameNo (0)
531 {
532 }
533 
535 {
536  m_nackedFrames.clear ();
537 }
538 
539 TypeId
541 {
542  static TypeId tid = TypeId ("ns3::UanHeaderRcAck")
543  .SetParent<Header> ()
544  .SetGroupName ("Uan")
545  .AddConstructor<UanHeaderRcAck> ()
546  ;
547  return tid;
548 }
549 
550 void
551 UanHeaderRcAck::SetFrameNo (uint8_t noFrames)
552 {
553  m_frameNo = noFrames;
554 }
555 
556 void
558 {
559  m_nackedFrames.insert (frame);
560 }
561 
562 const std::set<uint8_t> &
564 {
565  return m_nackedFrames;
566 }
567 
568 uint8_t
570 {
571  return m_frameNo;
572 }
573 
574 uint8_t
576 {
577  return m_nackedFrames.size ();
578 }
579 
580 uint32_t
582 {
583  return 1 + 1 + GetNoNacks ();
584 }
585 
586 void
588 {
589  start.WriteU8 (m_frameNo);
590  start.WriteU8 (GetNoNacks ());
591  std::set<uint8_t>::iterator it = m_nackedFrames.begin ();
592  for (; it != m_nackedFrames.end (); it++)
593  {
594  start.WriteU8 (*it);
595  }
596 }
597 
598 uint32_t
600 {
601  Buffer::Iterator rbuf = start;
602  m_frameNo = rbuf.ReadU8 ();
603  uint8_t noAcks = rbuf.ReadU8 ();
604  m_nackedFrames.clear ();
605  for (uint32_t i = 0; i < noAcks; i++)
606  {
607  m_nackedFrames.insert (rbuf.ReadU8 ());
608  }
609  return rbuf.GetDistanceFrom (start);
610 }
611 
612 void
613 UanHeaderRcAck::Print (std::ostream &os) const
614 {
615  os << "# Frames=" << (uint32_t) m_frameNo << " # nacked=" << (uint32_t) GetNoNacks () << " Nacked: ";
616  if (GetNoNacks () > 0)
617  {
618  std::set<uint8_t>::iterator it = m_nackedFrames.begin ();
619  os << (uint32_t) *it;
620  it++;
621  for (; it != m_nackedFrames.end (); it++)
622  {
623  os << ", " << (uint32_t) *it;
624  }
625  }
626 }
627 
628 TypeId
630 {
631  return GetTypeId ();
632 }
633 
634 } // namespace ns3
uint16_t ReadU16(void)
Definition: buffer.h:1029
Protocol header serialization and deserialization.
Definition: header.h:42
virtual void Serialize(Buffer::Iterator start) const
Time GetPropDelay(void) const
Get the propagation delay found in handshaking.
virtual uint32_t Deserialize(Buffer::Iterator start)
virtual void Serialize(Buffer::Iterator start) const
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
uint32_t ReadU32(void)
Definition: buffer.cc:975
uint8_t GetFrameNo(void) const
Get the reservation frame number being ACKed.
static TypeId GetTypeId(void)
Register this type.
void SetPropDelay(Time propDelay)
Set the propagation delay as found in handshaking.
Cycle broadcast information.
uint8_t GetRetryNo(void) const
Get the retry number of the RTS packet being cleared.
void SetRateNum(uint16_t rate)
Set the rate number corresponding to data rate of current cycle.
UanHeaderRcCtsGlobal()
Default constructor.
virtual uint32_t GetSerializedSize(void) const
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
Header used for ACK packets by protocol UanMacRc.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual uint32_t Deserialize(Buffer::Iterator start)
void SetAddress(UanAddress addr)
Set the destination address, for scheduling info.
uint8_t m_frameNo
Reservation frame number.
def start()
Definition: core.py:1790
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint16_t m_rateNum
Rate number.
Time m_winTime
Window time.
uint8_t m_frameNo
Next frame number.
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).
uint8_t GetFrameNo(void) const
Get the frame number.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:786
iterator in a Buffer instance
Definition: buffer.h:98
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
std::set< uint8_t > m_nackedFrames
Marker for nacked frames.
const std::set< uint8_t > & GetNackedFrames(void) const
Get the set of NACK'ed frames.
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint8_t m_retryNo
Retry number of received RTS packet.
Time GetTimeStamp(void) const
Get the transmit timestamp of this RTS packet.
void WriteU16(uint16_t data)
Definition: buffer.cc:873
virtual void Serialize(Buffer::Iterator start) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual void Print(std::ostream &os) const
UanAddress m_address
Destination of CTS packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
void AddNackedFrame(uint8_t frame)
NACK a frame.
virtual uint32_t Deserialize(Buffer::Iterator start)
Time m_delay
Delay until transmission.
uint8_t GetRetryNo(void) const
Get the retry number of this RTS packet.
UanAddress GetAddress(void) const
Get the destination address, for scheduling info.
void SetLength(uint16_t length)
Set the number of data bytes in the reservation.
uint8_t GetFrameNo(void) const
Get the frame number of the reservation being transmitted.
uint8_t GetAsInt(void) const
Convert to integer.
Definition: uan-address.cc:63
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.
Time GetRtsTimeStamp(void) const
Get the receive time of the RTS being cleared.
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.
virtual void Print(std::ostream &os) const
Time m_timeStampTx
Timestamp.
Time GetWindowTime(void) const
Get the window time (time duration following blocking time to allow RTS transmissions).
uint16_t GetRateNum(void) const
Get the data rate number.
virtual ~UanHeaderRcCts()
Destructor.
void SetTxTimeStamp(Time timeStamp)
Set the CTS timestamp.
uint8_t GetNoFrames(void) const
Get the number of data frames in the reservation.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetRtsTimeStamp(Time timeStamp)
Set the timestamp for RTS reception.
static TypeId GetTypeId(void)
Register this type.
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t m_frameNo
Data frame number.
Definition: uan-header-rc.h:98
UanHeaderRcData()
Default constructor.
virtual void Serialize(Buffer::Iterator start) const
uint16_t m_retryRate
Retry rate.
uint8_t GetNoNacks(void) const
Get the number of data frames being NACKed.
virtual void Serialize(Buffer::Iterator start) const
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 void Print(std::ostream &os) const
virtual ~UanHeaderRcRts()
Destructor.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
void SetFrameNo(uint8_t frameNo)
Set the frame number of the reservation being acknowledged.
UanHeaderRcCts()
Default constructor.
virtual uint32_t GetSerializedSize(void) const
uint16_t GetRetryRate(void) const
Get the retry rate number.
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint8_t GetFrameNo(void) const
Get the frame number of the RTS being cleared.
Time GetDelayToTx(void) const
Get the time delay from TX time of CTS packet until arrival of first data frame.
static TypeId GetTypeId(void)
Register this type.
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.
void WriteU32(uint32_t data)
Definition: buffer.cc:881
virtual uint32_t GetSerializedSize(void) const
uint8_t m_frameNo
Reservation frame number being cleared.
a unique identifier for an interface.
Definition: type-id.h:58
Time GetTxTimeStamp(void) const
Get the CTS transmit timestamp.
Time m_timeStamp
RTS TX timestamp.
static TypeId GetTypeId(void)
Register this type.
virtual uint32_t GetSerializedSize(void) const
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
void SetRetryNo(uint8_t no)
Set the retry number of this RTS packet.
uint8_t m_noFrames
Number of data frames in reservation.
Extra data header information.
Definition: uan-header-rc.h:41
UanHeaderRcAck()
Default constructor.
void SetFrameNo(uint8_t fno)
Set the frame number.
uint16_t GetLength(void) const
Get the total number of bytes in the reservation, including headers.
virtual void Print(std::ostream &os) const
virtual ~UanHeaderRcData()
Destructor.
virtual uint32_t GetSerializedSize(void) const