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  .SetGroupName ("Uan")
213  .AddConstructor<UanMacRc> ()
214  .AddAttribute ("RetryRate",
215  "Number of retry attempts per second (of RTS/GWPING).",
216  DoubleValue (1 / 5.0),
218  MakeDoubleChecker<double> ())
219  .AddAttribute ("MaxFrames",
220  "Maximum number of frames to include in a single RTS.",
221  UintegerValue (1),
223  MakeUintegerChecker<uint32_t> ())
224  .AddAttribute ("QueueLimit",
225  "Maximum packets to queue at MAC.",
226  UintegerValue (10),
228  MakeUintegerChecker<uint32_t> ())
229  .AddAttribute ("SIFS",
230  "Spacing to give between frames (this should match gateway).",
231  TimeValue (Seconds (0.2)),
233  MakeTimeChecker ())
234  .AddAttribute ("NumberOfRates",
235  "Number of rate divisions supported by each PHY.",
236  UintegerValue (0),
238  MakeUintegerChecker<uint32_t> ())
239  .AddAttribute ("MinRetryRate",
240  "Smallest allowed RTS retry rate.",
241  DoubleValue (0.01),
243  MakeDoubleChecker<double> ())
244  .AddAttribute ("RetryStep",
245  "Retry rate increment.",
246  DoubleValue (0.01),
248  MakeDoubleChecker<double> ())
249  .AddAttribute ("MaxPropDelay",
250  "Maximum possible propagation delay to gateway.",
251  TimeValue (Seconds (2)),
253  MakeTimeChecker ())
254  .AddTraceSource ("Enqueue",
255  "A (data) packet arrived at MAC for transmission.",
257  "ns3::UanMacRc::QueueTracedCallback")
258  .AddTraceSource ("Dequeue",
259  "A (data) packet was passed down to PHY from MAC.",
261  "ns3::UanMacRc::QueueTracedCallback")
262  .AddTraceSource ("RX",
263  "A packet was destined for and received at this MAC layer.",
265  "ns3::UanMac::PacketModeTracedCallback")
266  ;
267  return tid;
268 }
269 
270 int64_t
271 UanMacRc::AssignStreams (int64_t stream)
272 {
273  NS_LOG_FUNCTION (this << stream);
274  m_ev->SetStream (stream);
275  return 1;
276 }
277 
278 Address
280 {
281  return m_address;
282 }
283 
284 void
286 {
287  m_address = addr;
288 }
289 
290 bool
291 UanMacRc::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
292 {
293  if (protocolNumber > 0)
294  {
295  NS_LOG_WARN ("Warning: UanMacRc does not support multiple protocols. protocolNumber argument to Enqueue is being ignored");
296  }
297 
298 
299  if (m_pktQueue.size () >= m_queueLimit)
300  {
301  return false;
302  }
303 
304  m_pktQueue.push_back (std::make_pair (packet, UanAddress::ConvertFrom (dest)));
305 
306  switch (m_state)
307  {
308  case UNASSOCIATED:
309  Associate ();
310  return true;
311  case IDLE:
312  if (!m_rtsEvent.IsRunning ())
313  {
314  SendRts ();
315  }
316  return true;
317  case GWPSENT:
318  case RTSSENT:
319  case DATATX:
320  return true;
321  }
322 
323  return true;
324 }
325 
326 void
328 {
329  m_forwardUpCb = cb;
330 }
331 
332 void
334 {
335  m_phy = phy;
336  m_phy->SetReceiveOkCallback (MakeCallback (&UanMacRc::ReceiveOkFromPhy, this));
337 }
338 
339 Address
341 {
342  return UanAddress::GetBroadcast ();
343 }
344 
345 void
347 {
348 
349  UanHeaderCommon ch;
350  pkt->RemoveHeader (ch);
351  if (ch.GetDest () == m_address || ch.GetDest () == UanAddress::GetBroadcast ())
352  {
353  m_rxLogger (pkt, mode);
354  }
355 
356  switch (ch.GetType ())
357  {
358  case TYPE_DATA:
359 
360  if (ch.GetDest () == m_address)
361  {
362  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " UanMacRc Receiving DATA packet from PHY");
363  UanHeaderRcData dh;
364  pkt->RemoveHeader (dh);
365  m_forwardUpCb (pkt, ch.GetSrc ());
366  }
367  break;
368  case TYPE_RTS:
369  // Currently don't respond to RTS packets at non-gateway nodes
370  // (Code assumes single network neighberhood)
371  break;
372  case TYPE_CTS:
373  {
374  uint32_t ctsBytes = ch.GetSerializedSize () + pkt->GetSize ();
375  m_assocAddr = ch.GetSrc ();
377  pkt->RemoveHeader (ctsg);
378  m_currentRate = ctsg.GetRateNum ();
380 
381  UanHeaderRcRts rhtmp;
382 
383  Time winDelay = ctsg.GetWindowTime ();
384 
385  if (winDelay.GetSeconds () > 0)
386  {
387  m_rtsBlocked = false;
388  Simulator::Schedule (winDelay, &UanMacRc::BlockRtsing, this);
389  }
390  else
391  {
392  NS_FATAL_ERROR (Simulator::Now ().GetSeconds () << " Node " << m_address << " Received window period < 0");
393  }
394 
395  UanHeaderRcCts ctsh;
397  while (pkt->GetSize () > 0)
398  {
399  pkt->RemoveHeader (ctsh);
400  if (ctsh.GetAddress () == m_address)
401  {
402  if (m_state == GWPSENT)
403  {
404  m_assocAddr = ch.GetSrc ();
405  ScheduleData (ctsh, ctsg, ctsBytes);
406  }
407  else if (m_state == RTSSENT)
408  {
409  ScheduleData (ctsh, ctsg, ctsBytes);
410  }
411  else
412  {
413  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received CTS while state != RTSSENT or GWPING");
414  }
415  }
416  }
417  }
418  break;
419  case TYPE_GWPING:
420  // Do not respond to GWPINGS at non-gateway nodes
421  break;
422  case TYPE_ACK:
423  m_rtsBlocked = true;
424  if (ch.GetDest () != m_address)
425  {
426  return;
427  }
428  ProcessAck (pkt);
429  break;
430  default:
431  NS_FATAL_ERROR ("Unknown packet type " << ch.GetType () << " received at node " << GetAddress ());
432  }
433 
434 }
435 
436 void
437 UanMacRc::ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
438 {
440 
441 
442 
443  std::list<Reservation>::iterator it = m_resList.begin ();
444  for (; it != m_resList.end (); it++)
445  {
446  if (it->GetFrameNo () == ctsh.GetFrameNo ())
447  {
448  break;
449  }
450  }
451  if (it == m_resList.end ())
452  {
453  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received CTS packet with no corresponding reservation!");
454  return;
455  }
456  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received CTS packet. Scheduling data");
457  it->SetTransmitted ();
458 
459  double currentBps = m_phy->GetMode (m_currentRate).GetDataRateBps ();
460 
461  m_learnedProp = Simulator::Now () - ctsg.GetTxTimeStamp () - Seconds (ctsBytes * 8.0 / currentBps);
462 
463 
464  Time arrTime = ctsg.GetTxTimeStamp () + ctsh.GetDelayToTx ();
465  Time txTime = arrTime - m_learnedProp;
466 
467  Time startDelay = txTime - Simulator::Now ();
468 
469  Time frameDelay = Seconds (0);
470 
471  const std::list<std::pair <Ptr<Packet>, UanAddress > > l = it->GetPktList ();
472  std::list<std::pair <Ptr<Packet>, UanAddress > >::const_iterator pit;
473  pit = l.begin ();
474 
475 
476 
477  for (uint32_t i = 0; i < it->GetNoFrames (); i++, pit++)
478  {
479  Ptr<Packet> pkt = (*pit).first->Copy ();
480 
481  UanHeaderRcData dh;
482  dh.SetFrameNo (i);
483  dh.SetPropDelay (m_learnedProp);
484  pkt->AddHeader (dh);
485 
486  UanHeaderCommon ch;
487  ch.SetType (TYPE_DATA);
488  ch.SetDest (m_assocAddr);
489  ch.SetSrc (m_address);
490 
491  pkt->AddHeader (ch);
492  Time eventTime = startDelay + frameDelay;
493  if (eventTime.GetSeconds () < 0)
494  {
495  if (eventTime.GetSeconds () > -0.001)
496  {
497  eventTime = Seconds (0);
498  }
499  else
500  {
501  NS_FATAL_ERROR ("Scheduling error resulted in very negative data transmission time! eventTime = " << eventTime.GetSeconds ());
502  }
503  }
504  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 ());
505  Simulator::Schedule (eventTime, &UanMacRc::SendPacket, this, pkt, m_currentRate);
506  frameDelay = frameDelay + m_sifs + Seconds (pkt->GetSize () / currentBps);
507  }
508 
509  m_state = IDLE;
510  if (!m_pktQueue.empty ())
511  {
512 
513  if (m_rtsEvent.IsRunning ())
514  {
515  m_rtsEvent.Cancel ();
516  }
517 
518  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
519  double timeout = m_ev->GetValue ();
521  }
522 
523 }
524 
525 void
526 UanMacRc::SendPacket (Ptr<Packet> pkt, uint32_t rate)
527 {
528  UanHeaderCommon ch;
529  pkt->PeekHeader (ch);
530  std::string type;
531  switch (ch.GetType ())
532  {
533  case TYPE_DATA:
534  type = "DATA";
535  break;
536  case TYPE_RTS:
537  type = "RTS";
538  break;
539  case TYPE_CTS:
540  type = "CTS";
541  break;
542  case TYPE_ACK:
543  type = "ACK";
544  break;
545  case TYPE_GWPING:
546  type = "GWPING";
547  break;
548  default:
549  type = "UNKNOWN";
550  break;
551  }
552  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 ());
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>, UanAddress > > l = it->GetPktList ();
583  std::list<std::pair <Ptr<Packet>, UanAddress > >::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 (Simulator::Now ().GetSeconds () << " Node " << m_address << " Received NACK for " << (uint32_t) *nit);
592  while (pnum < *nit)
593  {
594  pit++;
595  pnum++;
596  }
597  UanHeaderRcData dh;
598  UanHeaderCommon ch;
599  m_pktQueue.push_front (*pit);
600  }
601  }
602  else
603  {
604  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " received ACK for all frames");
605  }
606  m_resList.erase (it);
607 }
608 
611 {
613 
614  rh.SetLength (res.GetLength ());
615  rh.SetNoFrames (res.GetNoFrames ());
616  rh.SetTimeStamp (res.GetTimestamp (res.GetRetryNo ()));
617  rh.SetFrameNo (res.GetFrameNo ());
618  rh.SetRetryNo (res.GetRetryNo ());
619  return rh;
620 }
621 
622 void
624 {
625  m_cntrlSends++;
626 
628  res.AddTimestamp (Simulator::Now ());
629  m_frameNo++;
630  m_resList.push_back (res);
631  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
632  bool phy1ok = IsPhy1Ok ();
633  if (phy1ok && !phyDual->IsPhy2Tx () & !m_rtsBlocked)
634  {
635  Ptr<Packet> pkt = Create<Packet> (0);
636  pkt->AddHeader (CreateRtsHeader (res));
638  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending first GWPING " << *pkt);
640  }
641  m_state = GWPSENT;
643  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
644  double timeout = m_ev->GetValue ();
646 }
647 
648 void
650 {
651  m_cntrlSends++;
652  if (m_state != GWPSENT)
653  {
654  return;
655  }
656  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
657  bool phy1ok = IsPhy1Ok ();
658  if (phy1ok && !phyDual->IsPhy2Tx () && !m_rtsBlocked)
659  {
660  Ptr<Packet> pkt = Create<Packet> ();
661 
662  Reservation res = m_resList.back ();
663  m_resList.pop_back ();
664  res.AddTimestamp (Simulator::Now ());
665  res.IncrementRetry ();
666 
667  pkt->AddHeader (CreateRtsHeader (res));
669 
671  m_resList.push_back (res);
672  }
674  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
675  double timeout = m_ev->GetValue ();
677 }
678 
679 
680 void
682 {
683  m_cntrlSends++;
684  if (m_state == RTSSENT)
685  {
686  return;
687  }
688 
689  NS_ASSERT (!m_pktQueue.empty ());
690 
692  res.AddTimestamp (Simulator::Now ());
693  m_frameNo++;
694  m_resList.push_back (res);
695  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
696  bool phy1ok = IsPhy1Ok ();
697  if (phy1ok && !phyDual->IsPhy2Tx () && !m_rtsBlocked )
698  {
699  Ptr<Packet> pkt = Create<Packet> (0);
700  pkt->AddHeader (CreateRtsHeader (res));
703  }
704  m_state = RTSSENT;
706  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
707  double timeout = m_ev->GetValue ();
709 
710 }
711 
712 // We assume here that packet types are known at detection.
713 bool
715 {
716  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
717 
718  bool phy1ok = true;
719  if (phyDual->IsPhy1Rx ())
720  {
721  Ptr<Packet> pkt = phyDual->GetPhy1PacketRx ();
722  UanHeaderCommon ch;
723  pkt->PeekHeader (ch);
724  if (ch.GetType () == TYPE_CTS || ch.GetType () == TYPE_ACK)
725  {
726  phy1ok = false;
727  }
728  else if (ch.GetDest () == m_address)
729  {
730  phy1ok = false;
731  }
732  }
733  return phy1ok;
734 }
735 
736 void
738 {
739  m_cntrlSends++;
740 
741  if (m_state != RTSSENT)
742  {
743  return;
744  }
745  Ptr<UanPhyDual> phyDual = m_phy->GetObject<UanPhyDual> ();
746 
747  bool phy1ok = IsPhy1Ok ();
748  if (phy1ok && !phyDual->IsPhy2Tx () && !m_rtsBlocked)
749  {
750 
751  if (m_resList.empty ())
752  {
753  NS_FATAL_ERROR (Simulator::Now ().GetSeconds () << " Node " << m_address << " tried to retry RTS with empty reservation list");
754  }
755  Ptr<Packet> pkt = Create<Packet> (0);
756 
757  Reservation res = m_resList.back ();
758  NS_ASSERT (!res.IsTransmitted ());
759  m_resList.pop_back ();
760  res.AddTimestamp (Simulator::Now ());
761  res.IncrementRetry ();
762  m_resList.push_back (res);
763  pkt->AddHeader (CreateRtsHeader (res));
766 
767  }
768  m_state = RTSSENT;
770  m_ev->SetAttribute ("Mean", DoubleValue (1 / m_retryRate));
771  double timeout = m_ev->GetValue ();
773 }
774 
775 void
777 {
778  m_rtsBlocked = true;
779 }
780 
781 } // namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:267
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 "...
uint8_t GetFrameNo(void) const
Get the reservation frame number being ACKed.
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:1176
void RtsTimeout(void)
Retry RTS.
Definition: uan-mac-rc.cc:737
void SetFrameNo(uint8_t frameNum)
Set the frame number of the reservation being transmitted.
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:217
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:714
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:224
Header used for ACK packets by protocol UanMacRc.
Associated with gateway.
Definition: uan-mac-rc.h:208
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
#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: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:796
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:226
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:228
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual Address GetAddress(void)
Get the MAC Address.
Definition: uan-mac-rc.cc:279
Finished scheduling packet sends.
Definition: uan-mac-rc.h:209
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:610
ns3::Time timeout
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:558
RTS just sent.
Definition: uan-mac-rc.h:210
uint8_t m_retryNo
Number of retries.
Definition: uan-mac-rc.h:142
network packets
Definition: packet.h:231
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:346
Non-gateway node MAC for reservation channel MAC protocol.
Definition: uan-mac-rc.h:163
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:340
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:446
void BlockRtsing(void)
Callback to block RST.
Definition: uan-mac-rc.cc:776
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:147
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:48
tuple phy
Definition: third.py:86
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1375
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:218
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:111
AttributeValue implementation for Time.
Definition: nstime.h:1055
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:251
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:327
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:230
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:231
bool IsTransmitted() const
Definition: uan-mac-rc.cc:123
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:247
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void SetDest(UanAddress dest)
Set the destination address.
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:316
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:239
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:221
#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:313
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:649
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:121
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:236
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:254
State m_state
MAC state.
Definition: uan-mac-rc.h:214
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:219
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:1056
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
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:271
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:215
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:249
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
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:241
virtual void SetAddress(UanAddress addr)
Set the address.
Definition: uan-mac-rc.cc:285
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:227
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
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:333
void SendRts(void)
Send RTS packet.
Definition: uan-mac-rc.cc:681
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:437
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:526
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
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:993
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:222
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
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:225
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:223
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:233
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:185
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:58
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:623
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
UanAddress m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:220
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:234
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
The callback to forward a packet up to higher layer.
Definition: uan-mac-rc.h:244
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
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:291
virtual uint32_t GetSerializedSize(void) const