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