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