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  ;
30 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcRts)
31  ;
32 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcCtsGlobal)
33  ;
34 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcCts)
35  ;
36 NS_OBJECT_ENSURE_REGISTERED (UanHeaderRcAck)
37  ;
38 
40  : Header (),
41  m_frameNo (0),
42  m_propDelay (Seconds (0))
43 {
44 }
45 
46 UanHeaderRcData::UanHeaderRcData (uint8_t frameNo, Time propDelay)
47  : Header (),
48  m_frameNo (frameNo),
49  m_propDelay (propDelay)
50 {
51 
52 }
53 
55 {
56 }
57 
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::UanHeaderRcData")
62  .SetParent<Header> ()
63  .AddConstructor<UanHeaderRcData> ()
64  ;
65  return tid;
66 }
67 
68 void
70 {
71  m_frameNo = no;
72 }
73 
74 void
76 {
77  m_propDelay = propDelay;
78 }
79 
80 uint8_t
82 {
83  return m_frameNo;
84 }
85 
86 Time
88 {
89  return m_propDelay;
90 }
91 
92 uint32_t
94 {
95  return 1 + 2;
96 }
97 
98 void
100 {
101  start.WriteU8 (m_frameNo);
102  start.WriteU16 ( (uint16_t)(1000.0 * m_propDelay.GetSeconds () + 0.5));
103 }
104 uint32_t
106 {
107  Buffer::Iterator rbuf = start;
108 
109  m_frameNo = start.ReadU8 ();
110  m_propDelay = Seconds ( ((double) start.ReadU16 ()) / 1000.0 );
111 
112  return rbuf.GetDistanceFrom (start);
113 }
114 
115 void
116 UanHeaderRcData::Print (std::ostream &os) const
117 {
118  os << "Frame No=" << (uint32_t) m_frameNo << " Prop Delay=" << m_propDelay.GetSeconds ();
119 }
120 
121 TypeId
123 {
124  return GetTypeId ();
125 }
126 
127 
129  : Header (),
130  m_frameNo (0),
131  m_noFrames (0),
132  m_length (0),
133  m_timeStamp (Seconds (0)),
134  m_retryNo (0)
135 {
136 
137 }
138 
139 UanHeaderRcRts::UanHeaderRcRts (uint8_t frameNo, uint8_t retryNo, uint8_t noFrames, uint16_t length, Time timeStamp)
140  : Header (),
141  m_frameNo (frameNo),
142  m_noFrames (noFrames),
143  m_length (length),
144  m_timeStamp (timeStamp),
145  m_retryNo (retryNo)
146 {
147 
148 }
149 
151 {
152 
153 }
154 
155 TypeId
157 {
158  static TypeId tid = TypeId ("ns3::UanHeaderRcRts")
159  .SetParent<Header> ()
160  .AddConstructor<UanHeaderRcRts> ()
161  ;
162  return tid;
163 
164 }
165 
166 void
168 {
169  m_frameNo = no;
170 }
171 
172 void
174 {
175  m_noFrames = no;
176 }
177 
178 void
179 UanHeaderRcRts::SetLength (uint16_t length)
180 {
181  m_length = length;
182 }
183 void
185 {
186  m_timeStamp = timeStamp;
187 }
188 
189 void
191 {
192  m_retryNo = no;
193 }
194 uint8_t
196 {
197  return m_noFrames;
198 }
199 
200 uint16_t
202 {
203  return m_length;
204 }
205 
206 Time
208 {
209  return m_timeStamp;
210 }
211 
212 uint8_t
214 {
215  return m_retryNo;
216 }
217 
218 uint8_t
220 {
221  return m_frameNo;
222 }
223 
224 uint32_t
226 {
227  return 1 + 1 + 1 + 4 + 2;
228 }
229 
230 void
232 {
233  start.WriteU8 (m_frameNo);
234  start.WriteU8 (m_retryNo);
235  start.WriteU8 (m_noFrames);
236  start.WriteU16 (m_length);
237  start.WriteU32 ((uint32_t)(m_timeStamp.GetSeconds () * 1000.0 + 0.5));
238  // start.WriteU16(uint16_t (m_timeStamp.GetSeconds ()*1000));
239 }
240 
241 uint32_t
243 {
244  Buffer::Iterator rbuf = start;
245  m_frameNo = rbuf.ReadU8 ();
246  m_retryNo = rbuf.ReadU8 ();
247  m_noFrames = rbuf.ReadU8 ();
248  m_length = rbuf.ReadU16 ();
249  m_timeStamp = Seconds ( ((double) rbuf.ReadU32 ()) / 1000.0 );
250  // m_timeStamp = Seconds ( rbuf.ReadU16 ()/1000 );
251  return rbuf.GetDistanceFrom (start);
252 }
253 
254 void
255 UanHeaderRcRts::Print (std::ostream &os) const
256 {
257  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 ();
258 }
259 
260 TypeId
262 {
263  return GetTypeId ();
264 }
265 
266 
267 
268 
270  : Header (),
271  m_retryRate (0),
272  m_rateNum (0)
273 {
274 
275 }
276 
277 UanHeaderRcCtsGlobal::UanHeaderRcCtsGlobal (Time wt, Time ts, uint16_t rate, uint16_t retryRate)
278  : Header (),
279  m_timeStampTx (ts),
280  m_winTime (wt),
281  m_retryRate (retryRate),
282  m_rateNum (rate)
283 {
284 
285 }
286 
288 {
289 
290 }
291 
292 TypeId
294 {
295  static TypeId tid = TypeId ("ns3::UanHeaderRcCtsGlobal")
296  .SetParent<Header> ()
297  .AddConstructor<UanHeaderRcCtsGlobal> ()
298  ;
299  return tid;
300 
301 }
302 
303 
304 void
306 {
307  m_rateNum = rate;
308 }
309 
310 void
312 {
313  m_retryRate = rate;
314 }
315 
316 void
318 {
319  m_winTime = t;
320 }
321 
322 void
324 {
325  m_timeStampTx = t;
326 }
327 
328 Time
330 {
331  return m_winTime;
332 }
333 
334 Time
336 {
337  return m_timeStampTx;
338 }
339 
340 uint16_t
342 {
343  return m_retryRate;
344 }
345 
346 uint16_t
348 {
349  return m_rateNum;
350 }
351 uint32_t
353 {
354  return 4 + 4 + 2 + 2;
355 }
356 
357 void
359 {
360  start.WriteU16 (m_rateNum);
361  start.WriteU16 (m_retryRate);
362  start.WriteU32 ( (uint32_t)(m_timeStampTx.GetSeconds () * 1000.0 + 0.5));
363  start.WriteU32 ( (uint32_t)(m_winTime.GetSeconds () * 1000.0 + 0.5));
364 }
365 
366 uint32_t
368 {
369  Buffer::Iterator rbuf = start;
370  m_rateNum = rbuf.ReadU16 ();
371  m_retryRate = rbuf.ReadU16 ();
372  m_timeStampTx = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
373  m_winTime = Seconds ( ( (double) rbuf.ReadU32 ()) / 1000.0 );
374  return rbuf.GetDistanceFrom (start);
375 
376 }
377 
378 void
379 UanHeaderRcCtsGlobal::Print (std::ostream &os) const
380 {
381  os << "CTS Global (Rate #=" << m_rateNum << ", Retry Rate=" << m_retryRate << ", TX Time=" << m_timeStampTx.GetSeconds () << ", Win Time=" << m_winTime.GetSeconds () << ")";
382 }
383 
384 TypeId
386 {
387  return GetTypeId ();
388 }
389 
391  : Header (),
392  m_frameNo (0),
393  m_timeStampRts (Seconds (0)),
394  m_retryNo (0),
395  m_delay (Seconds (0)),
396  m_address (UanAddress::GetBroadcast ())
397 {
398 
399 }
400 
401 UanHeaderRcCts::UanHeaderRcCts (uint8_t frameNo, uint8_t retryNo, Time ts, Time delay, UanAddress addr)
402  : Header (),
403  m_frameNo (frameNo),
404  m_timeStampRts (ts),
405  m_retryNo (retryNo),
406  m_delay (delay),
407  m_address (addr)
408 {
409 
410 }
411 
413 {
414 
415 }
416 
417 TypeId
419 {
420  static TypeId tid = TypeId ("ns3::UanHeaderRcCts")
421  .SetParent<Header> ()
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  start.WriteU8 (m_address.GetAsInt ());
499  start.WriteU8 (m_frameNo);
500  start.WriteU8 (m_retryNo);
501  start.WriteU32 ((uint32_t)(m_timeStampRts.GetSeconds () * 1000.0 + 0.5));
502  start.WriteU32 ((uint32_t)(m_delay.GetSeconds () * 1000.0 + 0.5));
503 }
504 
505 uint32_t
507 {
508  Buffer::Iterator rbuf = start;
509  m_address = UanAddress (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 
518 void
519 UanHeaderRcCts::Print (std::ostream &os) const
520 {
521  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 () << ")";
522 }
523 
524 TypeId
526 {
527  return GetTypeId ();
528 }
529 
531  : m_frameNo (0)
532 {
533 }
534 
536 {
537  m_nackedFrames.clear ();
538 }
539 
540 TypeId
542 {
543  static TypeId tid = TypeId ("ns3::UanHeaderRcAck")
544  .SetParent<Header> ()
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:845
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.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
uint32_t ReadU32(void)
Definition: buffer.cc:997
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.
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.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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:807
iterator in a Buffer instance
Definition: buffer.h:98
double GetSeconds(void) const
Definition: nstime.h:274
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:895
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:690
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:819
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:903
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:611
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