A Discrete-Event Network Simulator
API
 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 
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  .AddConstructor<UanHeaderRcData> ()
59  ;
60  return tid;
61 }
62 
63 void
65 {
66  m_frameNo = no;
67 }
68 
69 void
71 {
72  m_propDelay = propDelay;
73 }
74 
75 uint8_t
77 {
78  return m_frameNo;
79 }
80 
81 Time
83 {
84  return m_propDelay;
85 }
86 
87 uint32_t
89 {
90  return 1 + 2;
91 }
92 
93 void
95 {
96  start.WriteU8 (m_frameNo);
97  start.WriteU16 ( (uint16_t)(1000.0 * m_propDelay.GetSeconds () + 0.5));
98 }
99 uint32_t
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
118 {
119  return GetTypeId ();
120 }
121 
122 
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 
146 {
147 
148 }
149 
150 TypeId
152 {
153  static TypeId tid = TypeId ("ns3::UanHeaderRcRts")
154  .SetParent<Header> ()
155  .AddConstructor<UanHeaderRcRts> ()
156  ;
157  return tid;
158 
159 }
160 
161 void
163 {
164  m_frameNo = no;
165 }
166 
167 void
169 {
170  m_noFrames = no;
171 }
172 
173 void
174 UanHeaderRcRts::SetLength (uint16_t length)
175 {
176  m_length = length;
177 }
178 void
180 {
181  m_timeStamp = timeStamp;
182 }
183 
184 void
186 {
187  m_retryNo = no;
188 }
189 uint8_t
191 {
192  return m_noFrames;
193 }
194 
195 uint16_t
197 {
198  return m_length;
199 }
200 
201 Time
203 {
204  return m_timeStamp;
205 }
206 
207 uint8_t
209 {
210  return m_retryNo;
211 }
212 
213 uint8_t
215 {
216  return m_frameNo;
217 }
218 
219 uint32_t
221 {
222  return 1 + 1 + 1 + 4 + 2;
223 }
224 
225 void
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
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
257 {
258  return GetTypeId ();
259 }
260 
261 
262 
263 
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 
283 {
284 
285 }
286 
287 TypeId
289 {
290  static TypeId tid = TypeId ("ns3::UanHeaderRcCtsGlobal")
291  .SetParent<Header> ()
292  .AddConstructor<UanHeaderRcCtsGlobal> ()
293  ;
294  return tid;
295 
296 }
297 
298 
299 void
301 {
302  m_rateNum = rate;
303 }
304 
305 void
307 {
308  m_retryRate = rate;
309 }
310 
311 void
313 {
314  m_winTime = t;
315 }
316 
317 void
319 {
320  m_timeStampTx = t;
321 }
322 
323 Time
325 {
326  return m_winTime;
327 }
328 
329 Time
331 {
332  return m_timeStampTx;
333 }
334 
335 uint16_t
337 {
338  return m_retryRate;
339 }
340 
341 uint16_t
343 {
344  return m_rateNum;
345 }
346 uint32_t
348 {
349  return 4 + 4 + 2 + 2;
350 }
351 
352 void
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
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
381 {
382  return GetTypeId ();
383 }
384 
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 
408 {
409 
410 }
411 
412 TypeId
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
431 {
432  m_timeStampRts = timeStamp;
433 }
434 
435 
436 void
438 {
439  m_delay = delay;
440 }
441 
442 void
444 {
445  m_retryNo = no;
446 }
447 
448 void
450 {
451  m_address = addr;
452 }
453 uint8_t
455 {
456  return m_frameNo;
457 }
458 
459 Time
461 {
462  return m_timeStampRts;
463 }
464 
465 Time
467 {
468  return m_delay;
469 }
470 
471 uint8_t
473 {
474  return m_retryNo;
475 }
476 
479 {
480  return m_address;
481 }
482 
483 uint32_t
485 {
486  return 1 + 1 + 1 + 4 + 4;
487 }
488 
489 
490 void
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
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
521 {
522  return GetTypeId ();
523 }
524 
526  : m_frameNo (0)
527 {
528 }
529 
531 {
532  m_nackedFrames.clear ();
533 }
534 
535 TypeId
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
553 {
554  m_nackedFrames.insert (frame);
555 }
556 
557 const std::set<uint8_t> &
559 {
560  return m_nackedFrames;
561 }
562 
563 uint8_t
565 {
566  return m_frameNo;
567 }
568 
569 uint8_t
571 {
572  return m_nackedFrames.size ();
573 }
574 
575 uint32_t
577 {
578  return 1 + 1 + GetNoNacks ();
579 }
580 
581 void
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
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
625 {
626  return GetTypeId ();
627 }
628 
629 } // namespace ns3
uint16_t ReadU16(void)
Definition: buffer.h:1036
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:79
uint32_t ReadU32(void)
Definition: buffer.cc:1001
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.
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 the class in the ns-3 factory.
Definition: object-base.h:38
virtual TypeId GetInstanceTypeId(void) const
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.
virtual TypeId GetInstanceTypeId(void) const
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:811
iterator in a Buffer instance
Definition: buffer.h:98
double GetSeconds(void) const
Definition: nstime.h:272
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
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:899
virtual void Serialize(Buffer::Iterator start) const
virtual TypeId GetInstanceTypeId(void) const
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.
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
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:876
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.
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:1028
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:907
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:49
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)
Definition: type-id.cc:610
void SetRetryNo(uint8_t no)
Set the retry number of this RTS packet.
uint8_t m_noFrames
Number of data frames in reservation.
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