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