A Discrete-Event Network Simulator
API
uan-mac-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 #include "uan-mac-rc.h"
22 #include "uan-header-rc.h"
23 #include "uan-tx-mode.h"
24 #include "uan-phy.h"
25 #include "uan-header-common.h"
26 #include "uan-phy-dual.h"
27 
28 #include "ns3/log.h"
29 #include "ns3/nstime.h"
30 #include "ns3/simulator.h"
31 #include "ns3/assert.h"
32 #include "ns3/double.h"
33 #include "ns3/uinteger.h"
34 
35 #include <list>
36 #include <utility>
37 
38 
39 
40 namespace ns3 {
41 
42 NS_LOG_COMPONENT_DEFINE ("UanMacRc");
43 
45 
47  : m_length (0),
48  m_frameNo (0),
49  m_retryNo (0),
50  m_transmitted (false)
51 {
52 
53 }
54 
55 Reservation::Reservation (std::list<std::pair <Ptr<Packet>, UanAddress > > &list, uint8_t frameNo, uint32_t maxPkts)
56  : m_frameNo (frameNo),
57  m_retryNo (0),
58  m_transmitted (false)
59 {
60  uint32_t numPkts = (maxPkts) ? maxPkts : list.size ();
61  uint32_t length = 0;
62  UanHeaderRcData dh;
63  UanHeaderCommon ch;
64 
65  for (uint32_t i = 0; i < numPkts; i++)
66  {
67  length += list.front ().first->GetSize () +
68  ch.GetSerializedSize () +
69  dh.GetSerializedSize ();
70  m_pktList.push_back (list.front ());
71  list.pop_front ();
72  }
73  m_length = length;
74 }
75 
77 {
78  std::list<std::pair <Ptr<Packet>, UanAddress > >::iterator it;
79  for (it = m_pktList.begin (); it != m_pktList.end (); it++)
80  {
81  it->first = Ptr<Packet> ((Packet *) 0);
82  }
83  m_pktList.clear ();
84  m_timestamp.clear ();
85 }
86 uint32_t
88 {
89  return m_pktList.size ();
90 }
91 
92 uint32_t
94 {
95  return m_length;
96 }
97 
98 const std::list<std::pair <Ptr<Packet>, UanAddress > > &
100 {
101  return m_pktList;
102 }
103 
104 uint8_t
106 {
107  return m_frameNo;
108 }
109 
110 uint8_t
112 {
113  return m_retryNo;
114 }
115 
116 Time
117 Reservation::GetTimestamp (uint8_t n) const
118 {
119  return m_timestamp[n];
120 }
121 
122 bool
124 {
125  return m_transmitted;
126 }
127 
128 void
130 {
131  m_frameNo = fn;
132 }
133 
134 void
136 {
137  m_timestamp.push_back (t);
138 }
139 
140 void
142 {
143  m_retryNo++;
144 }
145 
146 void
148 {
149  m_transmitted = true;
150 }
151 
152 uint32_t UanMacRc::m_cntrlSends = 0;
153 
155  : UanMac (),
156  m_state (UNASSOCIATED),
157  m_rtsBlocked (false),
158  m_currentRate (10),
159  m_frameNo (0),
160  m_cleared (false)
161 {
162  m_ev = CreateObject<ExponentialRandomVariable> ();
163 
164  UanHeaderCommon ch;
165  UanHeaderRcCts ctsh;
167 
168  m_ctsSizeN = ctsh.GetSerializedSize ();
169  m_ctsSizeG = ch.GetSerializedSize () + ctsg.GetSerializedSize ();
170 }
171 
173 {
174 }
175 
176 void
178 {
179  if (m_cleared)
180  {
181  return;
182  }
183  m_cleared = true;
184  if (m_phy)
185  {
186  m_phy->Clear ();
187  m_phy = 0;
188  }
189  std::list<std::pair <Ptr<Packet>, UanAddress > >::iterator it;
190  for (it = m_pktQueue.begin (); it != m_pktQueue.end (); it++)
191  {
192  it->first = 0;
193  }
194  m_pktQueue.clear ();
195  m_resList.clear ();
196  m_startAgain.Cancel ();
197  m_rtsEvent.Cancel ();
198 }
199 
200 void
202 {
203  Clear ();
205 }
206 
207 TypeId
209 {
210  static TypeId tid = TypeId ("ns3::UanMacRc")
211  .SetParent<UanMac> ()
212  .AddConstructor<UanMacRc> ()
213  .AddAttribute ("RetryRate",
214  "Number of retry attempts per second (of RTS/GWPING).",
215  DoubleValue (1 / 5.0),
217  MakeDoubleChecker<double> ())
218  .AddAttribute ("MaxFrames",
219  "Maximum number of frames to include in a single RTS.",
220  UintegerValue (1),
222  MakeUintegerChecker<uint32_t> ())
223  .AddAttribute ("QueueLimit",
224  "Maximum packets to queue at MAC.",
225  UintegerValue (10),
227  MakeUintegerChecker<uint32_t> ())
228  .AddAttribute ("SIFS",
229  "Spacing to give between frames (this should match gateway).",
230  TimeValue (Seconds (0.2)),
232  MakeTimeChecker ())
233  .AddAttribute ("NumberOfRates",
234  "Number of rate divisions supported by each PHY.",
235  UintegerValue (0),
237  MakeUintegerChecker<uint32_t> ())
238  .AddAttribute ("MinRetryRate",
239  "Smallest allowed RTS retry rate.",
240  DoubleValue (0.01),
242  MakeDoubleChecker<double> ())
243  .AddAttribute ("RetryStep",
244  "Retry rate increment.",
245  DoubleValue (0.01),
247  MakeDoubleChecker<double> ())
248  .AddAttribute ("MaxPropDelay",
249  "Maximum possible propagation delay to gateway.",
250  TimeValue (Seconds (2)),
252  MakeTimeChecker ())
253  .AddTraceSource ("Enqueue",
254  "A (data) packet arrived at MAC for transmission.",
256  "ns3::UanMac::PacketModeTracedCallback")
257  .AddTraceSource ("Dequeue",
258  "A (data) packet was passed down to PHY from MAC.",
260  "ns3::UanMac::PacketModeTracedCallback")
261  .AddTraceSource ("RX",
262  "A packet was destined for and received at this MAC layer.",
264  "ns3::UanMac::PacketModeTracedCallback")
265  ;
266  return tid;
267 }
268 
269 int64_t
270 UanMacRc::AssignStreams (int64_t stream)
271 {
272  NS_LOG_FUNCTION (this << stream);
273  m_ev->SetStream (stream);
274  return 1;
275 }
276 
277 Address
279 {
280  return m_address;
281 }
282 
283 void
285 {
286  m_address = addr;
287 }
288 
289 bool
290 UanMacRc::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
291 {
292  if (protocolNumber > 0)
293  {
294  NS_LOG_WARN ("Warning: UanMacRc does not support multiple protocols. protocolNumber argument to Enqueue is being ignored");
295  }
296 
297 
298  if (m_pktQueue.size () >= m_queueLimit)
299  {
300  return false;
301  }
302 
303  m_pktQueue.push_back (std::make_pair (packet, UanAddress::ConvertFrom (dest)));
304 
305  switch (m_state)
306  {
307  case UNASSOCIATED:
308  Associate ();
309  return true;
310  case IDLE:
311  if (!m_rtsEvent.IsRunning ())
312  {
313  SendRts ();
314  }
315  return true;
316  case GWPSENT:
317  case RTSSENT:
318  case DATATX:
319  return true;
320  }
321 
322  return true;
323 }
324 
325 void
327 {
328  m_forwardUpCb = cb;
329 }
330 
331 void
333 {
334  m_phy = phy;
335  m_phy->SetReceiveOkCallback (MakeCallback (&UanMacRc::ReceiveOkFromPhy, this));
336 }
337 
338 Address
340 {
341  return UanAddress::GetBroadcast ();
342 }
343 
344 void
346 {
347 
348  UanHeaderCommon ch;
349  pkt->RemoveHeader (ch);
350  if (ch.GetDest () == m_address || ch.GetDest () == UanAddress::GetBroadcast ())
351  {
352  m_rxLogger (pkt, mode);
353  }
354 
355  switch (ch.GetType ())
356  {
357  case TYPE_DATA:
358 
359  if (ch.GetDest () == m_address)
360  {
361  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " UanMacRc Receiving DATA packet from PHY");
362  UanHeaderRcData dh;
363  pkt->RemoveHeader (dh);
364  m_forwardUpCb (pkt, ch.GetSrc ());
365  }
366  break;
367  case TYPE_RTS:
368  // Currently don't respond to RTS packets at non-gateway nodes
369  // (Code assumes single network neighberhood)
370  break;
371  case TYPE_CTS:
372  {
373  uint32_t ctsBytes = ch.GetSerializedSize () + pkt->GetSize ();
374  m_assocAddr = ch.GetSrc ();
376  pkt->RemoveHeader (ctsg);
377  m_currentRate = ctsg.GetRateNum ();
379 
380  UanHeaderRcRts rhtmp;
381 
382  Time winDelay = ctsg.GetWindowTime ();
383 
384  if (winDelay.GetSeconds () > 0)
385  {
386  m_rtsBlocked = false;
387  Simulator::Schedule (winDelay, &UanMacRc::BlockRtsing, this);
388  }
389  else
390  {
391  NS_FATAL_ERROR (Simulator::Now ().GetSeconds () << " Node " << m_address << " Received window period < 0");
392  }
393 
394  UanHeaderRcCts ctsh;
396  while (pkt->GetSize () > 0)
397  {
398  pkt->RemoveHeader (ctsh);
399  if (ctsh.GetAddress () == m_address)
400  {
401  if (m_state == GWPSENT)
402  {
403  m_assocAddr = ch.GetSrc ();
404  ScheduleData (ctsh, ctsg, ctsBytes);
405  }
406  else if (m_state == RTSSENT)
407  {
408  ScheduleData (ctsh, ctsg, ctsBytes);
409  }
410  else
411  {
412  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received CTS while state != RTSSENT or GWPING");
413  }
414  }
415  }
416  }
417  break;
418  case TYPE_GWPING:
419  // Do not respond to GWPINGS at non-gateway nodes
420  break;
421  case TYPE_ACK:
422  m_rtsBlocked = true;
423  if (ch.GetDest () != m_address)
424  {
425  return;
426  }
427  ProcessAck (pkt);
428  break;
429  default:
430  NS_FATAL_ERROR ("Unknown packet type " << ch.GetType () << " received at node " << GetAddress ());
431  }
432 
433 }
434 
435 void
436 UanMacRc::ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
437 {
439 
440 
441 
442  std::list<Reservation>::iterator it = m_resList.begin ();
443  for (; it != m_resList.end (); it++)
444  {
445  if (it->GetFrameNo () == ctsh.GetFrameNo ())
446  {
447  break;
448  }
449  }
450  if (it == m_resList.end ())
451  {
452  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received CTS packet with no corresponding reservation!");
453  return;
454  }
455  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received CTS packet. Scheduling data");
456  it->SetTransmitted ();
457 
458  double currentBps = m_phy->GetMode (m_currentRate).GetDataRateBps ();
459 
460  m_learnedProp = Simulator::Now () - ctsg.GetTxTimeStamp () - Seconds (ctsBytes * 8.0 / currentBps);
461 
462 
463  Time arrTime = ctsg.GetTxTimeStamp () + ctsh.GetDelayToTx ();
464  Time txTime = arrTime - m_learnedProp;
465 
466  Time startDelay = txTime - Simulator::Now ();
467 
468  Time frameDelay = Seconds (0);
469 
470  const std::list<std::pair <Ptr<Packet>, UanAddress > > l = it->GetPktList ();
471  std::list<std::pair <Ptr<Packet>, UanAddress > >::const_iterator pit;
472  pit = l.begin ();
473 
474 
475 
476  for (uint32_t i = 0; i < it->GetNoFrames (); i++, pit++)
477  {
478  Ptr<Packet> pkt = (*pit).first->Copy ();
479 
480  UanHeaderRcData dh;
481  dh.SetFrameNo (i);
482  dh.SetPropDelay (m_learnedProp);
483  pkt->AddHeader (dh);
484 
485  UanHeaderCommon ch;
486  ch.SetType (TYPE_DATA);
487  ch.SetDest (m_assocAddr);
488  ch.SetSrc (m_address);
489 
490  pkt->AddHeader (ch);
491  Time eventTime = startDelay + frameDelay;
492  if (eventTime.GetSeconds () < 0)
493  {
494  if (eventTime.GetSeconds () > -0.001)
495  {
496  eventTime = Seconds (0);
497  }
498  else
499  {
500  NS_FATAL_ERROR ("Scheduling error resulted in very negative data transmission time! eventTime = " << eventTime.GetSeconds ());
501  }
502  }
503  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " scheduling with delay " << eventTime.GetSeconds () << " propDelay " << m_learnedProp.GetSeconds () << " start delay " << startDelay.GetSeconds () << " arrival time " << arrTime.GetSeconds ());
504  Simulator::Schedule (eventTime, &UanMacRc::SendPacket, this, pkt, m_currentRate);
505  frameDelay = frameDelay + m_sifs + Seconds (pkt->GetSize () / currentBps);
506  }
507 
508  m_state = IDLE;
509  if (!m_pktQueue.empty ())
510  {
511 
512  if (m_rtsEvent.IsRunning ())
513  {
514  m_rtsEvent.Cancel ();
515  }
516 
517  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
518  double timeout = m_ev->GetValue ();
520  }
521 
522 }
523 
524 void
525 UanMacRc::SendPacket (Ptr<Packet> pkt, uint32_t rate)
526 {
527  UanHeaderCommon ch;
528  pkt->PeekHeader (ch);
529  std::string type;
530  switch (ch.GetType ())
531  {
532  case TYPE_DATA:
533  type = "DATA";
534  break;
535  case TYPE_RTS:
536  type = "RTS";
537  break;
538  case TYPE_CTS:
539  type = "CTS";
540  break;
541  case TYPE_ACK:
542  type = "ACK";
543  break;
544  case TYPE_GWPING:
545  type = "GWPING";
546  break;
547  default:
548  type = "UNKNOWN";
549  break;
550  }
551  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " transmitting " << pkt->GetSize () << " byte packet of type " << type << " with rate " << rate << "(" << m_phy->GetMode (rate).GetDataRateBps () << ") to " << ch.GetDest ());
552  m_dequeueLogger (pkt, rate);
553  m_phy->SendPacket (pkt, rate);
554 }
555 
556 void
558 {
559  UanHeaderRcAck ah;
560  ack->RemoveHeader (ah);
561 
562  std::list<Reservation>::iterator it = m_resList.begin ();
563  for (; it != m_resList.end (); it++)
564  {
565  if (it->GetFrameNo () == ah.GetFrameNo ())
566  {
567  break;
568  }
569  }
570  if (it == m_resList.end ())
571  {
572  NS_LOG_DEBUG ("In " << __func__ << " could not find reservation corresponding to received ACK");
573  return;
574  }
575  if (!it->IsTransmitted ())
576  {
577  return;
578  }
579  if (ah.GetNoNacks () > 0)
580  {
581  const std::list<std::pair <Ptr<Packet>, UanAddress > > l = it->GetPktList ();
582  std::list<std::pair <Ptr<Packet>, UanAddress > >::const_iterator pit;
583  pit = l.begin ();
584 
585  const std::set<uint8_t> &nacks = ah.GetNackedFrames ();
586  std::set<uint8_t>::iterator nit = nacks.begin ();
587  uint8_t pnum = 0;
588  for (; nit != nacks.end (); nit++)
589  {
590  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " Received NACK for " << (uint32_t) *nit);
591  while (pnum < *nit)
592  {
593  pit++;
594  pnum++;
595  }
596  UanHeaderRcData dh;
597  UanHeaderCommon ch;
598  m_pktQueue.push_front (*pit);
599  }
600  }
601  else
602  {
603  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received ACK for all frames");
604  }
605  m_resList.erase (it);
606 }
607 
610 {
612 
613  rh.SetLength (res.GetLength ());
614  rh.SetNoFrames (res.GetNoFrames ());
615  rh.SetTimeStamp (res.GetTimestamp (res.GetRetryNo ()));
616  rh.SetFrameNo (res.GetFrameNo ());
617  rh.SetRetryNo (res.GetRetryNo ());
618  return rh;
619 }
620 
621 void
623 {
624  m_cntrlSends++;
625 
627  res.AddTimestamp (Simulator::Now ());
628  m_frameNo++;
629  m_resList.push_back (res);
630  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
631  bool phy1ok = IsPhy1Ok ();
632  if (phy1ok && !phyDual->IsPhy2Tx () & !m_rtsBlocked)
633  {
634  Ptr<Packet> pkt = Create<Packet> (0);
635  pkt->AddHeader (CreateRtsHeader (res));
637  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending first GWPING " << *pkt);
639  }
640  m_state = GWPSENT;
642  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
643  double timeout = m_ev->GetValue ();
645 }
646 
647 void
649 {
650  m_cntrlSends++;
651  if (m_state != GWPSENT)
652  {
653  return;
654  }
655  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
656  bool phy1ok = IsPhy1Ok ();
657  if (phy1ok && !phyDual->IsPhy2Tx () && !m_rtsBlocked)
658  {
659  Ptr<Packet> pkt = Create<Packet> ();
660 
661  Reservation res = m_resList.back ();
662  m_resList.pop_back ();
663  res.AddTimestamp (Simulator::Now ());
664  res.IncrementRetry ();
665 
666  pkt->AddHeader (CreateRtsHeader (res));
668 
670  m_resList.push_back (res);
671  }
673  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
674  double timeout = m_ev->GetValue ();
676 }
677 
678 
679 void
681 {
682  m_cntrlSends++;
683  if (m_state == RTSSENT)
684  {
685  return;
686  }
687 
688  NS_ASSERT (!m_pktQueue.empty ());
689 
691  res.AddTimestamp (Simulator::Now ());
692  m_frameNo++;
693  m_resList.push_back (res);
694  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
695  bool phy1ok = IsPhy1Ok ();
696  if (phy1ok && !phyDual->IsPhy2Tx () && !m_rtsBlocked )
697  {
698  Ptr<Packet> pkt = Create<Packet> (0);
699  pkt->AddHeader (CreateRtsHeader (res));
702  }
703  m_state = RTSSENT;
705  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
706  double timeout = m_ev->GetValue ();
708 
709 }
710 
711 // We assume here that packet types are known at detection.
712 bool
714 {
715  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
716 
717  bool phy1ok = true;
718  if (phyDual->IsPhy1Rx ())
719  {
720  Ptr<Packet> pkt = phyDual->GetPhy1PacketRx ();
721  UanHeaderCommon ch;
722  pkt->PeekHeader (ch);
723  if (ch.GetType () == TYPE_CTS || ch.GetType () == TYPE_ACK)
724  {
725  phy1ok = false;
726  }
727  else if (ch.GetDest () == m_address)
728  {
729  phy1ok = false;
730  }
731  }
732  return phy1ok;
733 }
734 
735 void
737 {
738  m_cntrlSends++;
739 
740  if (m_state != RTSSENT)
741  {
742  return;
743  }
744  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
745 
746  bool phy1ok = IsPhy1Ok ();
747  if (phy1ok && !phyDual->IsPhy2Tx () && !m_rtsBlocked)
748  {
749 
750  if (m_resList.empty ())
751  {
752  NS_FATAL_ERROR (Simulator::Now ().GetSeconds () << " Node " << m_address << " tried to retry RTS with empty reservation list");
753  }
754  Ptr<Packet> pkt = Create<Packet> (0);
755 
756  Reservation res = m_resList.back ();
757  NS_ASSERT (!res.IsTransmitted ());
758  m_resList.pop_back ();
759  res.AddTimestamp (Simulator::Now ());
760  res.IncrementRetry ();
761  m_resList.push_back (res);
762  pkt->AddHeader (CreateRtsHeader (res));
765 
766  }
767  m_state = RTSSENT;
769  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
770  double timeout = m_ev->GetValue ();
772 }
773 
774 void
776 {
777  m_rtsBlocked = true;
778 }
779 
780 } // namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
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:95
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t GetFrameNo(void) const
Get the reservation frame number being ACKed.
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
void SetPropDelay(Time propDelay)
Set the propagation delay as found in handshaking.
Cycle broadcast information.
Callback template class.
Definition: callback.h:978
void RtsTimeout(void)
Retry RTS.
Definition: uan-mac-rc.cc:736
void SetFrameNo(uint8_t frameNum)
Set the frame number of the reservation being transmitted.
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:208
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:713
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:215
Header used for ACK packets by protocol UanMacRc.
Associated with gateway.
Definition: uan-mac-rc.h:199
void DoDispose()
Destructor implementation.
Definition: uan-mac-rc.cc:201
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
Definition: uan-mac-rc.cc:135
void SetAddress(UanAddress addr)
Set the destination address, for scheduling info.
uint8_t m_frameNo
Frame number.
Definition: uan-mac-rc.h:138
TracedCallback< Ptr< const Packet >, UanTxMode & > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:238
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
virtual ~UanMacRc()
Dummy destructor, DoDispose.
Definition: uan-mac-rc.cc:172
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:217
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:219
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
virtual Address GetAddress(void)
Get the MAC Address.
Definition: uan-mac-rc.cc:278
Finished scheduling packet sends.
Definition: uan-mac-rc.h:200
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:609
ns3::Time timeout
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:557
RTS just sent.
Definition: uan-mac-rc.h:201
uint8_t m_retryNo
Number of retries.
Definition: uan-mac-rc.h:142
network packets
Definition: packet.h:226
uint8_t GetType(void) const
Get the header type value.
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
Definition: uan-mac-rc.cc:345
uint32_t m_length
Total length of queued packets.
Definition: uan-mac-rc.h:136
a polymophic address class
Definition: address.h:90
virtual Address GetBroadcast(void) const
Get the broadcast address.
Definition: uan-mac-rc.cc:339
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
Definition: uan-mac-rc.cc:87
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:439
void BlockRtsing(void)
Callback to block RST.
Definition: uan-mac-rc.cc:775
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:147
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:242
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:327
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:48
Reservation()
Default constructor.
Definition: uan-mac-rc.cc:46
std::vector< Time > m_timestamp
Timestamps for each retry.
Definition: uan-mac-rc.h:140
UanAddress m_address
My addrese.s.
Definition: uan-mac-rc.h:209
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:111
AttributeValue implementation for Time.
Definition: nstime.h:921
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.
Definition: uan-mac-rc.cc:326
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 uint32_t GetSerializedSize(void) const
static UanAddress ConvertFrom(const Address &address)
Convert a generic address to a UanAddress.
Definition: uan-address.cc:54
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-rc.cc:177
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetSrc(UanAddress src)
Set the source address.
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc.h:221
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:222
bool IsTransmitted() const
Definition: uan-mac-rc.cc:123
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
void SetDest(UanAddress dest)
Set the destination address.
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:307
UanAddress GetAddress(void) const
Get the destination address, for scheduling info.
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktQueue
Pending packets.
Definition: uan-mac-rc.h:230
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:212
#define list
void SetLength(uint16_t length)
Set the number of data bytes in the reservation.
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
Definition: uan-mac-rc.h:304
static UanAddress GetBroadcast(void)
Get the broadcast address (255).
Definition: uan-address.cc:92
void AssociateTimeout(void)
Periodically retry association.
Definition: uan-mac-rc.cc:648
void SetFrameNo(uint8_t fn)
Set the frame number.
Definition: uan-mac-rc.cc:129
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-rc.h:227
UanMacRc()
Default constructor.
Definition: uan-mac-rc.cc:154
void SetTimeStamp(Time timeStamp)
Set RTS transmission time.
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-rc.cc:208
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Common packet header fields.
const std::list< std::pair< Ptr< Packet >, UanAddress > > & GetPktList(void) const
Get the list of packets.
Definition: uan-mac-rc.cc:99
UanAddress GetDest(void) const
Get the destination address.
EventId m_rtsEvent
The RTS event.
Definition: uan-mac-rc.h:245
State m_state
MAC state.
Definition: uan-mac-rc.h:205
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.
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
Definition: uan-mac-rc.h:210
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:922
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: uan-mac-rc.cc:270
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:206
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:240
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:232
virtual void SetAddress(UanAddress addr)
Set the address.
Definition: uan-mac-rc.cc:284
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:218
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
uint8_t GetNoNacks(void) const
Get the number of data frames being NACKed.
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-rc.cc:332
void SendRts(void)
Send RTS packet.
Definition: uan-mac-rc.cc:680
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:436
uint32_t GetLength() const
Get the total length of the Reservation.
Definition: uan-mac-rc.cc:93
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
Definition: uan-mac-rc.cc:525
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Stores reservation info for use in scheduling data channel by reservation channel MAC...
Definition: uan-mac-rc.h:52
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
uint8_t GetFrameNo() const
Get the frame number.
Definition: uan-mac-rc.cc:105
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc.h:213
double GetValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound...
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
virtual uint32_t GetSerializedSize(void) const
uint16_t GetRetryRate(void) const
Get the retry rate number.
void SetType(uint8_t type)
Set the header type.
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition: uan-mac-rc.h:216
Two channel Phy.
Definition: uan-phy-dual.h:82
UanAddress GetSrc(void) const
Get the source address.
uint8_t GetFrameNo(void) const
Get the frame number of the RTS being cleared.
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc.h:214
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktList
Queued packets for each address.
Definition: uan-mac-rc.h:134
Time GetDelayToTx(void) const
Get the time delay from TX time of CTS packet until arrival of first data frame.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition: uan-mac-rc.h:224
bool m_transmitted
Has this reservation been transmitted.
Definition: uan-mac-rc.h:144
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:190
virtual uint32_t GetSerializedSize(void) const
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:51
Time GetTxTimeStamp(void) const
Get the CTS transmit timestamp.
void Associate(void)
Associate with a gateway by sending the first GWPING.
Definition: uan-mac-rc.cc:622
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
UanAddress m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:211
void SetRetryNo(uint8_t no)
Set the retry number of this RTS packet.
void IncrementRetry()
Increment the retry count.
Definition: uan-mac-rc.cc:141
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc.h:225
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
The callback to forward a packet up to higher layer.
Definition: uan-mac-rc.h:235
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
Definition: uan-mac-rc.cc:117
~Reservation()
Destructor.
Definition: uan-mac-rc.cc:76
Extra data header information.
Definition: uan-header-rc.h:41
void SetFrameNo(uint8_t fno)
Set the frame number.
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
Definition: uan-mac-rc.cc:290
virtual uint32_t GetSerializedSize(void) const